| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/assert.h" | 5 #include "platform/assert.h" |
| 6 #include "vm/dart.h" | 6 #include "vm/dart.h" |
| 7 #include "vm/isolate.h" | 7 #include "vm/isolate.h" |
| 8 #include "vm/unit_test.h" | 8 #include "vm/unit_test.h" |
| 9 #include "vm/zone.h" | 9 #include "vm/zone.h" |
| 10 | 10 |
| 11 namespace dart { | 11 namespace dart { |
| 12 | 12 |
| 13 UNIT_TEST_CASE(AllocateZone) { | 13 VM_UNIT_TEST_CASE(AllocateZone) { |
| 14 #if defined(DEBUG) | 14 #if defined(DEBUG) |
| 15 FLAG_trace_zones = true; | 15 FLAG_trace_zones = true; |
| 16 #endif | 16 #endif |
| 17 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 17 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
| 18 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); | 18 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
| 19 Thread* thread = Thread::Current(); | 19 Thread* thread = Thread::Current(); |
| 20 EXPECT(thread->zone() == NULL); | 20 EXPECT(thread->zone() == NULL); |
| 21 { | 21 { |
| 22 StackZone stack_zone(thread); | 22 StackZone stack_zone(thread); |
| 23 EXPECT(thread->zone() != NULL); | 23 EXPECT(thread->zone() != NULL); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 EXPECT(buffer != NULL); | 65 EXPECT(buffer != NULL); |
| 66 buffer[(kSegmentSize + kWordSize) - 1] = 0; | 66 buffer[(kSegmentSize + kWordSize) - 1] = 0; |
| 67 allocated_size += (kSegmentSize + kWordSize); | 67 allocated_size += (kSegmentSize + kWordSize); |
| 68 EXPECT_LE(allocated_size, zone->SizeInBytes()); | 68 EXPECT_LE(allocated_size, zone->SizeInBytes()); |
| 69 } | 69 } |
| 70 EXPECT(thread->zone() == NULL); | 70 EXPECT(thread->zone() == NULL); |
| 71 Dart_ShutdownIsolate(); | 71 Dart_ShutdownIsolate(); |
| 72 } | 72 } |
| 73 | 73 |
| 74 | 74 |
| 75 UNIT_TEST_CASE(AllocGeneric_Success) { | 75 VM_UNIT_TEST_CASE(AllocGeneric_Success) { |
| 76 #if defined(DEBUG) | 76 #if defined(DEBUG) |
| 77 FLAG_trace_zones = true; | 77 FLAG_trace_zones = true; |
| 78 #endif | 78 #endif |
| 79 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 79 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
| 80 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); | 80 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
| 81 Thread* thread = Thread::Current(); | 81 Thread* thread = Thread::Current(); |
| 82 EXPECT(thread->zone() == NULL); | 82 EXPECT(thread->zone() == NULL); |
| 83 { | 83 { |
| 84 StackZone zone(thread); | 84 StackZone zone(thread); |
| 85 EXPECT(thread->zone() != NULL); | 85 EXPECT(thread->zone() != NULL); |
| 86 intptr_t allocated_size = 0; | 86 intptr_t allocated_size = 0; |
| 87 | 87 |
| 88 const intptr_t kNumElements = 1000; | 88 const intptr_t kNumElements = 1000; |
| 89 zone.GetZone()->Alloc<uint32_t>(kNumElements); | 89 zone.GetZone()->Alloc<uint32_t>(kNumElements); |
| 90 allocated_size += sizeof(uint32_t) * kNumElements; | 90 allocated_size += sizeof(uint32_t) * kNumElements; |
| 91 EXPECT_LE(allocated_size, zone.SizeInBytes()); | 91 EXPECT_LE(allocated_size, zone.SizeInBytes()); |
| 92 } | 92 } |
| 93 EXPECT(thread->zone() == NULL); | 93 EXPECT(thread->zone() == NULL); |
| 94 Dart_ShutdownIsolate(); | 94 Dart_ShutdownIsolate(); |
| 95 } | 95 } |
| 96 | 96 |
| 97 | 97 |
| 98 // This test is expected to crash. | 98 // This test is expected to crash. |
| 99 UNIT_TEST_CASE(AllocGeneric_Overflow) { | 99 VM_UNIT_TEST_CASE(AllocGeneric_Overflow) { |
| 100 #if defined(DEBUG) | 100 #if defined(DEBUG) |
| 101 FLAG_trace_zones = true; | 101 FLAG_trace_zones = true; |
| 102 #endif | 102 #endif |
| 103 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 103 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
| 104 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); | 104 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
| 105 Thread* thread = Thread::Current(); | 105 Thread* thread = Thread::Current(); |
| 106 EXPECT(thread->zone() == NULL); | 106 EXPECT(thread->zone() == NULL); |
| 107 { | 107 { |
| 108 StackZone zone(thread); | 108 StackZone zone(thread); |
| 109 EXPECT(thread->zone() != NULL); | 109 EXPECT(thread->zone() != NULL); |
| 110 | 110 |
| 111 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; | 111 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; |
| 112 zone.GetZone()->Alloc<uint32_t>(kNumElements); | 112 zone.GetZone()->Alloc<uint32_t>(kNumElements); |
| 113 } | 113 } |
| 114 Dart_ShutdownIsolate(); | 114 Dart_ShutdownIsolate(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 | 117 |
| 118 UNIT_TEST_CASE(ZoneAllocated) { | 118 VM_UNIT_TEST_CASE(ZoneAllocated) { |
| 119 #if defined(DEBUG) | 119 #if defined(DEBUG) |
| 120 FLAG_trace_zones = true; | 120 FLAG_trace_zones = true; |
| 121 #endif | 121 #endif |
| 122 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 122 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
| 123 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); | 123 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
| 124 Thread* thread = Thread::Current(); | 124 Thread* thread = Thread::Current(); |
| 125 EXPECT(thread->zone() == NULL); | 125 EXPECT(thread->zone() == NULL); |
| 126 static int marker; | 126 static int marker; |
| 127 | 127 |
| 128 class SimpleZoneObject : public ZoneAllocated { | 128 class SimpleZoneObject : public ZoneAllocated { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 | 164 |
| 165 | 165 |
| 166 TEST_CASE(PrintToString) { | 166 TEST_CASE(PrintToString) { |
| 167 StackZone zone(Thread::Current()); | 167 StackZone zone(Thread::Current()); |
| 168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); | 168 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); |
| 169 EXPECT_STREQ("Hello World!", result); | 169 EXPECT_STREQ("Hello World!", result); |
| 170 } | 170 } |
| 171 | 171 |
| 172 | 172 |
| 173 #ifndef PRODUCT | 173 #ifndef PRODUCT |
| 174 UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) { | 174 VM_UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) { |
| 175 #if defined(DEBUG) | 175 #if defined(DEBUG) |
| 176 FLAG_trace_zones = true; | 176 FLAG_trace_zones = true; |
| 177 #endif | 177 #endif |
| 178 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, | 178 Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_data, |
| 179 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); | 179 bin::core_isolate_snapshot_instructions, NULL, NULL, NULL); |
| 180 Thread* thread = Thread::Current(); | 180 Thread* thread = Thread::Current(); |
| 181 EXPECT(thread->zone() == NULL); | 181 EXPECT(thread->zone() == NULL); |
| 182 { | 182 { |
| 183 StackZone zone(thread); | 183 StackZone zone(thread); |
| 184 StackZone string_stack_zone(thread); | 184 StackZone string_stack_zone(thread); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 EXPECT_LE(zone.SizeInBytes(), zone.CapacityInBytes()); | 222 EXPECT_LE(zone.SizeInBytes(), zone.CapacityInBytes()); |
| 223 EXPECT_SUBSTRING(size_buf, json); | 223 EXPECT_SUBSTRING(size_buf, json); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 EXPECT(thread->zone() == NULL); | 226 EXPECT(thread->zone() == NULL); |
| 227 Dart_ShutdownIsolate(); | 227 Dart_ShutdownIsolate(); |
| 228 } | 228 } |
| 229 #endif | 229 #endif |
| 230 | 230 |
| 231 | 231 |
| 232 UNIT_TEST_CASE(NativeScopeZoneAllocation) { | 232 VM_UNIT_TEST_CASE(NativeScopeZoneAllocation) { |
| 233 ASSERT(ApiNativeScope::Current() == NULL); | 233 ASSERT(ApiNativeScope::Current() == NULL); |
| 234 ASSERT(Thread::Current() == NULL); | 234 ASSERT(Thread::Current() == NULL); |
| 235 EXPECT_EQ(0, ApiNativeScope::current_memory_usage()); | 235 EXPECT_EQ(0, ApiNativeScope::current_memory_usage()); |
| 236 { | 236 { |
| 237 ApiNativeScope scope; | 237 ApiNativeScope scope; |
| 238 EXPECT_EQ(scope.zone()->CapacityInBytes(), | 238 EXPECT_EQ(scope.zone()->CapacityInBytes(), |
| 239 ApiNativeScope::current_memory_usage()); | 239 ApiNativeScope::current_memory_usage()); |
| 240 (void)Dart_ScopeAllocate(2048); | 240 (void)Dart_ScopeAllocate(2048); |
| 241 EXPECT_EQ(scope.zone()->CapacityInBytes(), | 241 EXPECT_EQ(scope.zone()->CapacityInBytes(), |
| 242 ApiNativeScope::current_memory_usage()); | 242 ApiNativeScope::current_memory_usage()); |
| 243 } | 243 } |
| 244 EXPECT_EQ(0, ApiNativeScope::current_memory_usage()); | 244 EXPECT_EQ(0, ApiNativeScope::current_memory_usage()); |
| 245 } | 245 } |
| 246 | 246 |
| 247 } // namespace dart | 247 } // namespace dart |
| OLD | NEW |