Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(54)

Side by Side Diff: runtime/vm/dart_api_message.cc

Issue 1151113002: Move bootstrap scripts and token streams to the VM isolate so that they become read only objects. T… (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Address code review comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "vm/dart_api_message.h" 5 #include "vm/dart_api_message.h"
6 #include "vm/object.h" 6 #include "vm/object.h"
7 #include "vm/snapshot_ids.h" 7 #include "vm/snapshot_ids.h"
8 #include "vm/symbols.h" 8 #include "vm/symbols.h"
9 #include "vm/unicode.h" 9 #include "vm/unicode.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 static const int kNumInitialReferences = 4; 13 static const int kNumInitialReferences = 4;
14 14
15 ApiMessageReader::ApiMessageReader(const uint8_t* buffer, 15 ApiMessageReader::ApiMessageReader(const uint8_t* buffer,
16 intptr_t length, 16 intptr_t length,
17 ReAlloc alloc, 17 ReAlloc alloc,
18 bool use_vm_isolate_snapshot) 18 bool use_vm_isolate_snapshot)
19 : BaseReader(buffer, length), 19 : BaseReader(buffer, length),
20 alloc_(alloc), 20 alloc_(alloc),
21 backward_references_(kNumInitialReferences), 21 backward_references_(kNumInitialReferences),
22 vm_isolate_references_(kNumInitialReferences),
22 vm_symbol_references_(NULL), 23 vm_symbol_references_(NULL),
23 max_vm_isolate_object_id_( 24 max_vm_isolate_object_id_(
24 use_vm_isolate_snapshot ? 25 use_vm_isolate_snapshot ?
25 Object::vm_isolate_snapshot_object_table().Length() : 0) { 26 Object::vm_isolate_snapshot_object_table().Length() : 0) {
26 Init(); 27 Init();
27 } 28 }
28 29
29 30
30 void ApiMessageReader::Init() { 31 void ApiMessageReader::Init() {
31 // Initialize marker objects used to handle Lists. 32 // Initialize marker objects used to handle Lists.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 if (length > 0) { 194 if (length > 0) {
194 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1); 195 value->value.as_array.values = reinterpret_cast<Dart_CObject**>(value + 1);
195 } else { 196 } else {
196 value->value.as_array.values = NULL; 197 value->value.as_array.values = NULL;
197 } 198 }
198 return value; 199 return value;
199 } 200 }
200 201
201 202
202 Dart_CObject* ApiMessageReader::AllocateDartCObjectVmIsolateObj(intptr_t id) { 203 Dart_CObject* ApiMessageReader::AllocateDartCObjectVmIsolateObj(intptr_t id) {
203 return CreateDartCObjectString(VmIsolateSnapshotObject(id)); 204 RawObject* raw = VmIsolateSnapshotObject(id);
205 intptr_t cid = raw->GetClassId();
206 switch (cid) {
207 case kOneByteStringCid: {
208 RawOneByteString* raw_str = reinterpret_cast<RawOneByteString*>(raw);
209 const char* str = reinterpret_cast<const char*>(raw_str->ptr()->data());
210 ASSERT(str != NULL);
211 Dart_CObject* object = NULL;
212 for (intptr_t i = 0; i < vm_isolate_references_.length(); i++) {
213 object = vm_isolate_references_.At(i);
214 if ((object->type == Dart_CObject_kString)) {
215 if (strcmp(str, const_cast<char*>(object->value.as_string)) == 0) {
216 return object;
217 }
218 }
219 }
220 object = CreateDartCObjectString(raw);
221 vm_isolate_references_.Add(object);
222 return object;
223 }
224
225 case kMintCid: {
226 const Mint& obj = Mint::Handle(reinterpret_cast<RawMint*>(raw));
227 int64_t value64 = obj.value();
228 if ((kMinInt32 <= value64) && (value64 <= kMaxInt32)) {
229 return GetCanonicalMintObject(Dart_CObject_kInt32, value64);
230 } else {
231 return GetCanonicalMintObject(Dart_CObject_kInt64, value64);
232 }
233 }
234
235 default:
236 UNREACHABLE();
237 return NULL;
238 }
204 } 239 }
205 240
206 241
207 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal( 242 Dart_CObject_Internal* ApiMessageReader::AllocateDartCObjectInternal(
208 Dart_CObject_Internal::Type type) { 243 Dart_CObject_Internal::Type type) {
209 Dart_CObject_Internal* value = 244 Dart_CObject_Internal* value =
210 reinterpret_cast<Dart_CObject_Internal*>( 245 reinterpret_cast<Dart_CObject_Internal*>(
211 alloc_(NULL, 0, sizeof(Dart_CObject_Internal))); 246 alloc_(NULL, 0, sizeof(Dart_CObject_Internal)));
212 ASSERT(value != NULL); 247 ASSERT(value != NULL);
213 value->type = static_cast<Dart_CObject_Type>(type); 248 value->type = static_cast<Dart_CObject_Type>(type);
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 RawOneByteString* raw_str = reinterpret_cast<RawOneByteString*>(raw); 431 RawOneByteString* raw_str = reinterpret_cast<RawOneByteString*>(raw);
397 intptr_t len = Smi::Value(raw_str->ptr()->length_); 432 intptr_t len = Smi::Value(raw_str->ptr()->length_);
398 Dart_CObject* object = AllocateDartCObjectString(len); 433 Dart_CObject* object = AllocateDartCObjectString(len);
399 char* p = object->value.as_string; 434 char* p = object->value.as_string;
400 memmove(p, raw_str->ptr()->data(), len); 435 memmove(p, raw_str->ptr()->data(), len);
401 p[len] = '\0'; 436 p[len] = '\0';
402 return object; 437 return object;
403 } 438 }
404 439
405 440
441 Dart_CObject* ApiMessageReader::GetCanonicalMintObject(Dart_CObject_Type type,
442 int64_t value64) {
443 Dart_CObject* object = NULL;
444 for (intptr_t i = 0; i < vm_isolate_references_.length(); i++) {
445 object = vm_isolate_references_.At(i);
446 if (object->type == type) {
447 if (value64 == object->value.as_int64) {
448 return object;
449 }
450 }
451 }
452 if (type == Dart_CObject_kInt32) {
453 object = AllocateDartCObjectInt32(static_cast<int32_t>(value64));
454 } else {
455 object = AllocateDartCObjectInt64(value64);
456 }
457 vm_isolate_references_.Add(object);
458 return object;
459 }
460
461
406 Dart_CObject* ApiMessageReader::ReadObjectRef() { 462 Dart_CObject* ApiMessageReader::ReadObjectRef() {
407 int64_t value64 = Read<int64_t>(); 463 int64_t value64 = Read<int64_t>();
408 if ((value64 & kSmiTagMask) == 0) { 464 if ((value64 & kSmiTagMask) == 0) {
409 int64_t untagged_value = value64 >> kSmiTagShift; 465 int64_t untagged_value = value64 >> kSmiTagShift;
410 if ((kMinInt32 <= untagged_value) && (untagged_value <= kMaxInt32)) { 466 if ((kMinInt32 <= untagged_value) && (untagged_value <= kMaxInt32)) {
411 return AllocateDartCObjectInt32(static_cast<int32_t>(untagged_value)); 467 return AllocateDartCObjectInt32(static_cast<int32_t>(untagged_value));
412 } else { 468 } else {
413 return AllocateDartCObjectInt64(untagged_value); 469 return AllocateDartCObjectInt64(untagged_value);
414 } 470 }
415 } 471 }
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 if (!success) { 1303 if (!success) {
1248 UnmarkAllCObjects(object); 1304 UnmarkAllCObjects(object);
1249 return false; 1305 return false;
1250 } 1306 }
1251 } 1307 }
1252 UnmarkAllCObjects(object); 1308 UnmarkAllCObjects(object);
1253 return true; 1309 return true;
1254 } 1310 }
1255 1311
1256 } // namespace dart 1312 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_message.h ('k') | runtime/vm/object.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698