Chromium Code Reviews| 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 |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 Dart_ShutdownIsolate(); | 162 Dart_ShutdownIsolate(); |
| 163 } | 163 } |
| 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 | |
| 173 #ifndef PRODUCT | |
| 174 UNIT_TEST_CASE(PrintZoneMemoryInfoToJSON) { | |
| 175 #if defined(DEBUG) | |
| 176 FLAG_trace_zones = true; | |
| 177 #endif | |
|
siva
2016/12/09 02:49:39
trace_zones does not seem to be used in this metho
bkonyi
2016/12/09 17:52:57
I added this since it appears in all of the zone t
| |
| 178 Dart_CreateIsolate(NULL, NULL, bin::isolate_snapshot_buffer, NULL, NULL, | |
| 179 NULL); | |
| 180 Thread* thread = Thread::Current(); | |
| 181 EXPECT(thread->zone() == NULL); | |
| 182 { | |
| 183 StackZone zone(thread); | |
| 184 EXPECT(thread->zone() != NULL); | |
| 185 | |
| 186 intptr_t allocated_size = 0; | |
| 187 const intptr_t kNumElements = 1000; | |
| 188 | |
| 189 zone.GetZone()->Alloc<uint32_t>(kNumElements); | |
| 190 allocated_size += sizeof(uint32_t) * kNumElements; | |
| 191 | |
| 192 EXPECT_LE(allocated_size, zone.SizeInBytes()); | |
| 193 { | |
| 194 JSONStream stream; | |
| 195 // Get the JSON formated zone information. | |
| 196 zone.GetZone()->PrintJSON(&stream); | |
| 197 const char* json = stream.ToCString(); | |
| 198 char size_buf[64]; | |
| 199 | |
| 200 // Ensure that address and size matches actual values. | |
| 201 OS::SNPrint(size_buf, sizeof(size_buf), | |
| 202 "\"capacity\":%ld," | |
| 203 "\"used\":%ld", | |
| 204 zone.SizeInBytes(), zone.UsedSizeInBytes()); | |
| 205 EXPECT_SUBSTRING(size_buf, json); | |
| 206 } | |
| 207 | |
| 208 // Expand the zone to ensure that JSON is updated accordingly. | |
| 209 zone.GetZone()->Alloc<uint32_t>(kNumElements); | |
| 210 allocated_size += sizeof(uint32_t) * kNumElements; | |
| 211 EXPECT_LE(allocated_size, zone.SizeInBytes()); | |
| 212 { | |
| 213 JSONStream stream; | |
| 214 zone.GetZone()->PrintJSON(&stream); | |
| 215 const char* json = stream.ToCString(); | |
| 216 char size_buf[64]; | |
| 217 | |
| 218 OS::SNPrint(size_buf, sizeof(size_buf), | |
| 219 "\"capacity\":%ld," | |
| 220 "\"used\":%ld", | |
| 221 zone.SizeInBytes(), zone.UsedSizeInBytes()); | |
| 222 EXPECT_SUBSTRING(size_buf, json); | |
| 223 } | |
| 224 } | |
| 225 EXPECT(thread->zone() == NULL); | |
| 226 Dart_ShutdownIsolate(); | |
| 227 } | |
| 228 #endif | |
| 229 | |
| 172 } // namespace dart | 230 } // namespace dart |
| OLD | NEW |