| 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 DECLARE_DEBUG_FLAG(bool, trace_zones); | 13 DECLARE_DEBUG_FLAG(bool, trace_zones); |
| 14 | 14 |
| 15 UNIT_TEST_CASE(AllocateZone) { | 15 UNIT_TEST_CASE(AllocateZone) { |
| 16 #if defined(DEBUG) | 16 #if defined(DEBUG) |
| 17 FLAG_trace_zones = true; | 17 FLAG_trace_zones = true; |
| 18 #endif | 18 #endif |
| 19 Isolate* isolate = Isolate::Init(NULL); | 19 Isolate::Flags vm_flags; |
| 20 Dart_IsolateFlags api_flags; |
| 21 vm_flags.CopyTo(&api_flags); |
| 22 Isolate* isolate = Isolate::Init(NULL, api_flags); |
| 20 EXPECT(Isolate::Current() == isolate); | 23 EXPECT(Isolate::Current() == isolate); |
| 21 EXPECT(isolate->current_zone() == NULL); | 24 EXPECT(isolate->current_zone() == NULL); |
| 22 { | 25 { |
| 23 StackZone stack_zone(isolate); | 26 StackZone stack_zone(isolate); |
| 24 EXPECT(isolate->current_zone() != NULL); | 27 EXPECT(isolate->current_zone() != NULL); |
| 25 Zone* zone = stack_zone.GetZone(); | 28 Zone* zone = stack_zone.GetZone(); |
| 26 intptr_t allocated_size = 0; | 29 intptr_t allocated_size = 0; |
| 27 | 30 |
| 28 // The loop is to make sure we overflow one segment and go on | 31 // The loop is to make sure we overflow one segment and go on |
| 29 // to the next segment. | 32 // to the next segment. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 EXPECT(isolate->current_zone() == NULL); | 74 EXPECT(isolate->current_zone() == NULL); |
| 72 isolate->Shutdown(); | 75 isolate->Shutdown(); |
| 73 delete isolate; | 76 delete isolate; |
| 74 } | 77 } |
| 75 | 78 |
| 76 | 79 |
| 77 UNIT_TEST_CASE(AllocGeneric_Success) { | 80 UNIT_TEST_CASE(AllocGeneric_Success) { |
| 78 #if defined(DEBUG) | 81 #if defined(DEBUG) |
| 79 FLAG_trace_zones = true; | 82 FLAG_trace_zones = true; |
| 80 #endif | 83 #endif |
| 81 Isolate* isolate = Isolate::Init(NULL); | 84 Isolate::Flags vm_flags; |
| 85 Dart_IsolateFlags api_flags; |
| 86 vm_flags.CopyTo(&api_flags); |
| 87 Isolate* isolate = Isolate::Init(NULL, api_flags); |
| 82 EXPECT(Isolate::Current() == isolate); | 88 EXPECT(Isolate::Current() == isolate); |
| 83 EXPECT(isolate->current_zone() == NULL); | 89 EXPECT(isolate->current_zone() == NULL); |
| 84 { | 90 { |
| 85 StackZone zone(isolate); | 91 StackZone zone(isolate); |
| 86 EXPECT(isolate->current_zone() != NULL); | 92 EXPECT(isolate->current_zone() != NULL); |
| 87 intptr_t allocated_size = 0; | 93 intptr_t allocated_size = 0; |
| 88 | 94 |
| 89 const intptr_t kNumElements = 1000; | 95 const intptr_t kNumElements = 1000; |
| 90 zone.GetZone()->Alloc<uint32_t>(kNumElements); | 96 zone.GetZone()->Alloc<uint32_t>(kNumElements); |
| 91 allocated_size += sizeof(uint32_t) * kNumElements; | 97 allocated_size += sizeof(uint32_t) * kNumElements; |
| 92 EXPECT_LE(allocated_size, zone.SizeInBytes()); | 98 EXPECT_LE(allocated_size, zone.SizeInBytes()); |
| 93 } | 99 } |
| 94 EXPECT(isolate->current_zone() == NULL); | 100 EXPECT(isolate->current_zone() == NULL); |
| 95 isolate->Shutdown(); | 101 isolate->Shutdown(); |
| 96 delete isolate; | 102 delete isolate; |
| 97 } | 103 } |
| 98 | 104 |
| 99 | 105 |
| 100 // This test is expected to crash. | 106 // This test is expected to crash. |
| 101 UNIT_TEST_CASE(AllocGeneric_Overflow) { | 107 UNIT_TEST_CASE(AllocGeneric_Overflow) { |
| 102 #if defined(DEBUG) | 108 #if defined(DEBUG) |
| 103 FLAG_trace_zones = true; | 109 FLAG_trace_zones = true; |
| 104 #endif | 110 #endif |
| 105 Isolate* isolate = Isolate::Init(NULL); | 111 Isolate::Flags vm_flags; |
| 112 Dart_IsolateFlags api_flags; |
| 113 vm_flags.CopyTo(&api_flags); |
| 114 Isolate* isolate = Isolate::Init(NULL, api_flags); |
| 106 EXPECT(Isolate::Current() == isolate); | 115 EXPECT(Isolate::Current() == isolate); |
| 107 EXPECT(isolate->current_zone() == NULL); | 116 EXPECT(isolate->current_zone() == NULL); |
| 108 { | 117 { |
| 109 StackZone zone(isolate); | 118 StackZone zone(isolate); |
| 110 EXPECT(isolate->current_zone() != NULL); | 119 EXPECT(isolate->current_zone() != NULL); |
| 111 | 120 |
| 112 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; | 121 const intptr_t kNumElements = (kIntptrMax / sizeof(uint32_t)) + 1; |
| 113 zone.GetZone()->Alloc<uint32_t>(kNumElements); | 122 zone.GetZone()->Alloc<uint32_t>(kNumElements); |
| 114 } | 123 } |
| 115 isolate->Shutdown(); | 124 isolate->Shutdown(); |
| 116 delete isolate; | 125 delete isolate; |
| 117 } | 126 } |
| 118 | 127 |
| 119 | 128 |
| 120 UNIT_TEST_CASE(ZoneAllocated) { | 129 UNIT_TEST_CASE(ZoneAllocated) { |
| 121 #if defined(DEBUG) | 130 #if defined(DEBUG) |
| 122 FLAG_trace_zones = true; | 131 FLAG_trace_zones = true; |
| 123 #endif | 132 #endif |
| 124 Isolate* isolate = Isolate::Init(NULL); | 133 Isolate::Flags vm_flags; |
| 134 Dart_IsolateFlags api_flags; |
| 135 vm_flags.CopyTo(&api_flags); |
| 136 Isolate* isolate = Isolate::Init(NULL, api_flags); |
| 125 EXPECT(Isolate::Current() == isolate); | 137 EXPECT(Isolate::Current() == isolate); |
| 126 EXPECT(isolate->current_zone() == NULL); | 138 EXPECT(isolate->current_zone() == NULL); |
| 127 static int marker; | 139 static int marker; |
| 128 | 140 |
| 129 class SimpleZoneObject : public ZoneAllocated { | 141 class SimpleZoneObject : public ZoneAllocated { |
| 130 public: | 142 public: |
| 131 SimpleZoneObject() : slot(marker++) { } | 143 SimpleZoneObject() : slot(marker++) { } |
| 132 virtual ~SimpleZoneObject() { } | 144 virtual ~SimpleZoneObject() { } |
| 133 virtual int GetSlot() { return slot; } | 145 virtual int GetSlot() { return slot; } |
| 134 int slot; | 146 int slot; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 165 } | 177 } |
| 166 | 178 |
| 167 | 179 |
| 168 TEST_CASE(PrintToString) { | 180 TEST_CASE(PrintToString) { |
| 169 StackZone zone(Isolate::Current()); | 181 StackZone zone(Isolate::Current()); |
| 170 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); | 182 const char* result = zone.GetZone()->PrintToString("Hello %s!", "World"); |
| 171 EXPECT_STREQ("Hello World!", result); | 183 EXPECT_STREQ("Hello World!", result); |
| 172 } | 184 } |
| 173 | 185 |
| 174 } // namespace dart | 186 } // namespace dart |
| OLD | NEW |