| 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 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::isolate_snapshot_buffer, NULL, NULL, |   17   Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 
|   18                      NULL); |   18                      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); | 
|   24     Zone* zone = stack_zone.GetZone(); |   24     Zone* zone = stack_zone.GetZone(); | 
|   25     intptr_t allocated_size = 0; |   25     intptr_t allocated_size = 0; | 
|   26  |   26  | 
|   27     // The loop is to make sure we overflow one segment and go on |   27     // The loop is to make sure we overflow one segment and go on | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   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 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::isolate_snapshot_buffer, NULL, NULL, |   79   Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 
|   80                      NULL); |   80                      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 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::isolate_snapshot_buffer, NULL, NULL, |  103   Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 
|  104                      NULL); |  104                      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 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::isolate_snapshot_buffer, NULL, NULL, |  122   Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 
|  123                      NULL); |  123                      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 { | 
|  129    public: |  129    public: | 
|  130     SimpleZoneObject() : slot(marker++) {} |  130     SimpleZoneObject() : slot(marker++) {} | 
|  131     virtual ~SimpleZoneObject() {} |  131     virtual ~SimpleZoneObject() {} | 
|  132     virtual int GetSlot() { return slot; } |  132     virtual int GetSlot() { return slot; } | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  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 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::isolate_snapshot_buffer, NULL, NULL, |  178   Dart_CreateIsolate(NULL, NULL, bin::core_isolate_snapshot_buffer, NULL, NULL, | 
|  179                      NULL); |  179                      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); | 
|  185     EXPECT(thread->zone() != NULL); |  185     EXPECT(thread->zone() != NULL); | 
|  186  |  186  | 
|  187     intptr_t allocated_size = 0; |  187     intptr_t allocated_size = 0; | 
|  188     const intptr_t kNumElements = 1000; |  188     const intptr_t kNumElements = 1000; | 
| (...skipping 33 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 }  // namespace dart |  231 }  // namespace dart | 
| OLD | NEW |