class LoadStoreAnalysisTest : public CommonCompilerTest, public OptimizingUnitTestHelper { public:
LoadStoreAnalysisTest() {
use_boot_image_ = true; // Make the Runtime creation cheaper.
}
};
TEST_F(LoadStoreAnalysisTest, ArrayHeapLocations) {
HBasicBlock* main = InitEntryMainExitGraphWithReturnVoid();
// Test HeapLocationCollector initialization. // Should be no heap locations, no operations on the heap.
ScopedArenaAllocator allocator(graph_->GetArenaStack());
HeapLocationCollector heap_location_collector(graph_, &allocator);
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 0U);
ASSERT_FALSE(heap_location_collector.HasHeapStores());
// Test that after visiting the graph_, it must see following heap locations // array[c1], array[c2], array[index]; and it should see heap stores.
heap_location_collector.VisitBasicBlock(main);
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 3U);
ASSERT_TRUE(heap_location_collector.HasHeapStores());
// Test queries on HeapLocationCollector's ref info and index records.
ReferenceInfo* ref = heap_location_collector.FindReferenceInfoOf(array);
DataType::Type type = DataType::Type::kInt32;
size_t field = HeapLocation::kInvalidFieldOffset;
size_t vec = HeapLocation::kScalar;
size_t class_def = HeapLocation::kDeclaringClassDefIndexForArrays; constbool is_vec_op = false;
size_t loc1 = heap_location_collector.FindHeapLocationIndex(
ref, type, field, c1, vec, class_def, is_vec_op);
size_t loc2 = heap_location_collector.FindHeapLocationIndex(
ref, type, field, c2, vec, class_def, is_vec_op);
size_t loc3 = heap_location_collector.FindHeapLocationIndex(
ref, type, field, index, vec, class_def, is_vec_op); // must find this reference info for array in HeapLocationCollector.
ASSERT_TRUE(ref != nullptr); // must find these heap locations; // and array[1], array[2], array[3] should be different heap locations.
ASSERT_TRUE(loc1 != HeapLocationCollector::kHeapLocationNotFound);
ASSERT_TRUE(loc2 != HeapLocationCollector::kHeapLocationNotFound);
ASSERT_TRUE(loc3 != HeapLocationCollector::kHeapLocationNotFound);
ASSERT_TRUE(loc1 != loc2);
ASSERT_TRUE(loc2 != loc3);
ASSERT_TRUE(loc1 != loc3);
// Test alias relationships after building aliasing matrix. // array[1] and array[2] clearly should not alias; // array[index] should alias with the others, because index is an unknow value.
heap_location_collector.BuildAliasingMatrix();
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc3));
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc3));
EXPECT_TRUE(CheckGraph());
}
TEST_F(LoadStoreAnalysisTest, FieldHeapLocations) {
HBasicBlock* main = InitEntryMainExitGraphWithReturnVoid();
// Test HeapLocationCollector initialization. // Should be no heap locations, no operations on the heap.
ScopedArenaAllocator allocator(graph_->GetArenaStack());
HeapLocationCollector heap_location_collector(graph_, &allocator);
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 0U);
ASSERT_FALSE(heap_location_collector.HasHeapStores());
// Test that after visiting the graph, it must see following heap locations // object.field10, object.field20 and it should see heap stores.
heap_location_collector.VisitBasicBlock(main);
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 2U);
ASSERT_TRUE(heap_location_collector.HasHeapStores());
// Test queries on HeapLocationCollector's ref info and index records.
ReferenceInfo* ref = heap_location_collector.FindReferenceInfoOf(object);
size_t loc1 = heap_location_collector.GetFieldHeapLocation(object, &get_field10->GetFieldInfo());
size_t loc2 = heap_location_collector.GetFieldHeapLocation(object, &get_field20->GetFieldInfo()); // must find references info for object and in HeapLocationCollector.
ASSERT_TRUE(ref != nullptr); // must find these heap locations.
ASSERT_TRUE(loc1 != HeapLocationCollector::kHeapLocationNotFound);
ASSERT_TRUE(loc2 != HeapLocationCollector::kHeapLocationNotFound); // different fields of same object.
ASSERT_TRUE(loc1 != loc2); // accesses to different fields of the same object should not alias.
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
EXPECT_TRUE(CheckGraph());
}
TEST_F(LoadStoreAnalysisTest, ArrayIndexAliasingTest) {
HBasicBlock* body = InitEntryMainExitGraphWithReturnVoid();
// LSA/HeapLocationCollector should see those ArrayGet instructions.
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 8U);
ASSERT_TRUE(heap_location_collector.HasHeapStores());
// Test queries on HeapLocationCollector's aliasing matrix after load store analysis.
size_t loc1 = HeapLocationCollector::kHeapLocationNotFound;
size_t loc2 = HeapLocationCollector::kHeapLocationNotFound;
// Test alias: array[0] and array[1]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set1);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set2);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+0] and array[i-0]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set3);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set5);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+1] and array[i-1]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set4);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set6);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+1] and array[1-i]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set4);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set7);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+1] and array[i-(-1)]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set4);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set8);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// LSA/HeapLocationCollector should see those instructions.
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 10U);
ASSERT_TRUE(heap_location_collector.HasHeapStores());
// Test queries on HeapLocationCollector's aliasing matrix after load store analysis.
size_t loc1, loc2;
// Test alias: array[0] and array[0,1,2,3]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_0);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_0);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[0] and array[1,2,3,4]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_0);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_1);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[0] and array[8,9,10,11]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_0);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_8);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[1] and array[8,9,10,11]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_1);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_8);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[1] and array[0,1,2,3]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_1);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_0);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[0,1,2,3] and array[8,9,10,11]
loc1 = heap_location_collector.GetArrayHeapLocation(vstore_0);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_8);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[0,1,2,3] and array[1,2,3,4]
loc1 = heap_location_collector.GetArrayHeapLocation(vstore_0);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_1);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[0] and array[i,i+1,i+2,i+3]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_0);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_i);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i] and array[0,1,2,3]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_0);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i] and array[i,i+1,i+2,i+3]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_i);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i] and array[i+8,i+9,i+10,i+11]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_i);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_i_add8);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+6,i+7,i+8,i+9] and array[i+8,i+9,i+10,i+11] // Test partial overlap.
loc1 = heap_location_collector.GetArrayHeapLocation(vstore_i_add6);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_i_add8);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+6,i+7] and array[i,i+1,i+2,i+3] // Test different vector lengths.
loc1 = heap_location_collector.GetArrayHeapLocation(vstore_i_add6_vlen2);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_i);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+6,i+7] and array[i+8,i+9,i+10,i+11]
loc1 = heap_location_collector.GetArrayHeapLocation(vstore_i_add6_vlen2);
loc2 = heap_location_collector.GetArrayHeapLocation(vstore_i_add8);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
}
TEST_F(LoadStoreAnalysisTest, ArrayIndexCalculationOverflowTest) {
HBasicBlock* main = InitEntryMainExitGraphWithReturnVoid();
HInstruction* array = MakeParam(DataType::Type::kReference);
HInstruction* index = MakeParam(DataType::Type::kInt32);
// LSA/HeapLocationCollector should see those ArrayGet instructions.
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 8U);
ASSERT_TRUE(heap_location_collector.HasHeapStores());
// Test queries on HeapLocationCollector's aliasing matrix after load store analysis.
size_t loc1 = HeapLocationCollector::kHeapLocationNotFound;
size_t loc2 = HeapLocationCollector::kHeapLocationNotFound;
// Test alias: array[i+0x80000000] and array[i-0x80000000]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_1);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_2);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+0x10] and array[i-0xFFFFFFF0]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_3);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_4);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+0x7FFFFFFF] and array[i-0x80000001]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_5);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_6);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Test alias: array[i+0] and array[i-0]
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_7);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_8);
ASSERT_TRUE(heap_location_collector.MayAlias(loc1, loc2));
// Should not alias:
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_2);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_6);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
// Should not alias:
loc1 = heap_location_collector.GetArrayHeapLocation(arr_set_7);
loc2 = heap_location_collector.GetArrayHeapLocation(arr_set_2);
ASSERT_FALSE(heap_location_collector.MayAlias(loc1, loc2));
}
TEST_F(LoadStoreAnalysisTest, TestHuntOriginalRef) {
HBasicBlock* main = InitEntryMainExitGraphWithReturnVoid();
// Test that the HeapLocationCollector should be able to tell // that there is only ONE array location, no matter how many // times the original reference has been transformed by BoundType, // NullCheck, IntermediateAddress, etc.
ASSERT_EQ(heap_location_collector.GetNumberOfHeapLocations(), 1U);
size_t loc1 = heap_location_collector.GetArrayHeapLocation(array_get1);
size_t loc2 = heap_location_collector.GetArrayHeapLocation(array_get2);
size_t loc3 = heap_location_collector.GetArrayHeapLocation(array_get3);
size_t loc4 = heap_location_collector.GetArrayHeapLocation(array_get4);
ASSERT_TRUE(loc1 != HeapLocationCollector::kHeapLocationNotFound);
ASSERT_EQ(loc1, loc2);
ASSERT_EQ(loc1, loc3);
ASSERT_EQ(loc1, loc4);
}
// // IF_BLOCK // obj = new Obj(); // if (parameter_value) { // // LEFT // call_func(obj); // } else { // // RIGHT // obj.f0 = 0; // call_func2(obj); // } // // RETURN_BLOCK // obj.f0;
TEST_F(LoadStoreAnalysisTest, TotalEscape) {
HBasicBlock* return_block = InitEntryMainExitGraphWithReturnVoid(); auto [if_block, left, right] = CreateDiamondPattern(return_block);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.