forked from facebook/redex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
do not re-order methods from perf-sensitive classes
Summary: Keep the original order of methods belonging to perf sensitive classes. Reviewed By: amnn Differential Revision: D27823070 fbshipit-source-id: 8f3e8c45b21bf6dca1b95217fc26518dbb0ca6e4
- Loading branch information
1 parent
75cbbda
commit d020da4
Showing
5 changed files
with
252 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <json/json.h> | ||
|
||
#include "ControlFlow.h" | ||
#include "DexInstruction.h" | ||
#include "DexPosition.h" | ||
#include "DexUtil.h" | ||
#include "IODIMetadata.h" | ||
#include "IRCode.h" | ||
#include "InstructionLowering.h" | ||
#include "RedexTest.h" | ||
#include "Show.h" | ||
#include "Walkers.h" | ||
|
||
#include "DexOutput.h" | ||
|
||
class DexOutputTest : public RedexIntegrationTest { | ||
public: | ||
DexOutputTest() {} | ||
|
||
std::vector<DexMethod*> get_ordered_methods(DexOutput& dout) { | ||
std::vector<DexMethod*> code_items; | ||
for (auto& ci : dout.m_code_item_emits) { | ||
code_items.push_back(ci.method); | ||
} | ||
return code_items; | ||
} | ||
}; | ||
|
||
TEST_F(DexOutputTest, testSimilarityOrderer) { | ||
std::vector<SortMode> sort_modes{SortMode::METHOD_PROFILED_ORDER, | ||
SortMode::METHOD_SIMILARITY}; | ||
|
||
Json::Value cfg; | ||
ConfigFiles config_files(cfg); | ||
std::unique_ptr<PositionMapper> pos_mapper(PositionMapper::make("")); | ||
auto scope = build_class_scope(stores); | ||
|
||
// Lower the code | ||
walk::parallel::methods<>( | ||
scope, [](DexMethod* m) { instruction_lowering::lower(m, true); }); | ||
|
||
DexOutput dout("", &*classes, nullptr, true, 0, 0, | ||
DebugInfoKind::NoCustomSymbolication, nullptr, config_files, | ||
pos_mapper.get(), nullptr, nullptr, nullptr, 25); | ||
|
||
dout.prepare(SortMode::DEFAULT, sort_modes, config_files, "dex\n039"); | ||
auto code_items = get_ordered_methods(dout); | ||
|
||
uint32_t i = 0; | ||
std::vector<std::string> method_names(code_items.size()); | ||
for (auto* m : code_items) { | ||
method_names[i++] = show(m); | ||
} | ||
|
||
std::vector<std::string> expected_order = { | ||
"LDexOutputTest$NonPerfSensitiveClass;.<init>:(LDexOutputTest;)V", | ||
"LDexOutputTest$PerfSensitiveClass;.<init>:(LDexOutputTest;)V", | ||
"LDexOutputTest$SecondPerfSensitiveClass;.<init>:(LDexOutputTest;)V", | ||
"LDexOutputTest$NonPerfSensitiveClass;.EjustReturnFive:()I", | ||
"LDexOutputTest$PerfSensitiveClass;.EjustReturnFive:()I", | ||
"LDexOutputTest$SecondPerfSensitiveClass;.EjustReturnFive:()I", | ||
"LDexOutputTest;.AjustReturnFive:()I", | ||
"LDexOutputTest;.EjustReturnFive:()I", | ||
"LDexOutputTest$NonPerfSensitiveClass;.FsomeLogic:(I)I", | ||
"LDexOutputTest$PerfSensitiveClass;.FsomeLogic:(I)I", | ||
"LDexOutputTest$SecondPerfSensitiveClass;.FsomeLogic:(I)I", | ||
"LDexOutputTest;.CsomeLogic:(I)I", | ||
"LDexOutputTest;.FsomeLogic:(I)I", | ||
"LDexOutputTest;.HsomeLogic:(I)I", | ||
"LDexOutputTest;.<init>:()V", | ||
"LDexOutputTest;.BjustCallSixpublic:()I", | ||
"LDexOutputTest;.GjustCallSixpublic:()I", | ||
"LDexOutputTest;.DgetSixpublic:()I"}; | ||
|
||
EXPECT_TRUE(std::equal(method_names.begin(), method_names.end(), | ||
expected_order.begin())); | ||
} | ||
|
||
TEST_F(DexOutputTest, testPerfSensitive) { | ||
std::vector<SortMode> sort_modes{SortMode::METHOD_PROFILED_ORDER, | ||
SortMode::METHOD_SIMILARITY}; | ||
|
||
Json::Value cfg; | ||
ConfigFiles config_files(cfg); | ||
std::unique_ptr<PositionMapper> pos_mapper(PositionMapper::make("")); | ||
|
||
(*classes)[1]->set_perf_sensitive(true); | ||
(*classes)[2]->set_perf_sensitive(true); | ||
|
||
auto scope = build_class_scope(stores); | ||
|
||
// Lower the code | ||
walk::parallel::methods<>( | ||
scope, [](DexMethod* m) { instruction_lowering::lower(m, true); }); | ||
|
||
DexOutput dout("", &*classes, nullptr, true, 0, 0, | ||
DebugInfoKind::NoCustomSymbolication, nullptr, config_files, | ||
pos_mapper.get(), nullptr, nullptr, nullptr, 25); | ||
|
||
dout.prepare(SortMode::DEFAULT, sort_modes, config_files, "dex\n039"); | ||
auto code_items = get_ordered_methods(dout); | ||
|
||
uint32_t i = 0; | ||
std::vector<std::string> method_names(code_items.size()); | ||
for (auto* m : code_items) { | ||
method_names[i++] = show(m); | ||
} | ||
|
||
std::vector<std::string> expected_order = { | ||
"LDexOutputTest$NonPerfSensitiveClass;.<init>:(LDexOutputTest;)V", | ||
"LDexOutputTest$NonPerfSensitiveClass;.EjustReturnFive:()I", | ||
"LDexOutputTest;.AjustReturnFive:()I", | ||
"LDexOutputTest;.EjustReturnFive:()I", | ||
"LDexOutputTest$NonPerfSensitiveClass;.FsomeLogic:(I)I", | ||
"LDexOutputTest$PerfSensitiveClass;.<init>:(LDexOutputTest;)V", | ||
"LDexOutputTest$PerfSensitiveClass;.EjustReturnFive:()I", | ||
"LDexOutputTest$PerfSensitiveClass;.FsomeLogic:(I)I", | ||
"LDexOutputTest$SecondPerfSensitiveClass;.<init>:(LDexOutputTest;)V", | ||
"LDexOutputTest$SecondPerfSensitiveClass;.EjustReturnFive:()I", | ||
"LDexOutputTest$SecondPerfSensitiveClass;.FsomeLogic:(I)I", | ||
"LDexOutputTest;.<init>:()V", | ||
"LDexOutputTest;.BjustCallSixpublic:()I", | ||
"LDexOutputTest;.GjustCallSixpublic:()I", | ||
"LDexOutputTest;.CsomeLogic:(I)I", | ||
"LDexOutputTest;.FsomeLogic:(I)I", | ||
"LDexOutputTest;.HsomeLogic:(I)I", | ||
"LDexOutputTest;.DgetSixpublic:()I"}; | ||
|
||
EXPECT_TRUE(std::equal(method_names.begin(), method_names.end(), | ||
expected_order.begin())); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
public class DexOutputTest { | ||
public static int AjustReturnFive() { | ||
return 5; | ||
} | ||
|
||
public int BjustCallSixpublic() { | ||
return DgetSixpublic(); | ||
} | ||
|
||
public int CsomeLogic(int y) { | ||
int x = 0; | ||
x = x / y; | ||
x++; | ||
return x; | ||
} | ||
|
||
public int DgetSixpublic() { | ||
return 6; | ||
} | ||
|
||
public static int EjustReturnFive() { | ||
return 5; | ||
} | ||
|
||
public int FsomeLogic(int y) { | ||
int x = 0; | ||
x = x / y; | ||
x++; | ||
return x; | ||
} | ||
|
||
public int GjustCallSixpublic() { | ||
return DgetSixpublic(); | ||
} | ||
|
||
public int HsomeLogic(int y) { | ||
int x = 0; | ||
x = x / y; | ||
x++; | ||
return x; | ||
} | ||
|
||
class PerfSensitiveClass { | ||
public int FsomeLogic(int y) { | ||
int x = 0; | ||
x = x / y; | ||
x++; | ||
return x; | ||
} | ||
|
||
public int EjustReturnFive() { | ||
return 5; | ||
} | ||
} | ||
|
||
class NonPerfSensitiveClass { | ||
public int FsomeLogic(int y) { | ||
int x = 0; | ||
x = x / y; | ||
x++; | ||
return x; | ||
} | ||
|
||
public int EjustReturnFive() { | ||
return 5; | ||
} | ||
} | ||
|
||
class SecondPerfSensitiveClass { | ||
public int FsomeLogic(int y) { | ||
int x = 0; | ||
x = x / y; | ||
x++; | ||
return x; | ||
} | ||
|
||
public int EjustReturnFive() { | ||
return 5; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters