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

Side by Side Diff: vm/dart_api_message.cc

Issue 11745022: - Make Boolean 'true' and 'false' singleton VM isolate objects. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 7 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « vm/dart_api_message.h ('k') | vm/dart_api_state.h » ('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
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 value->value.as_array.values[i] = ReadObjectRef(); 208 value->value.as_array.values[i] = ReadObjectRef();
209 } 209 }
210 return value; 210 return value;
211 } 211 }
212 212
213 return ReadInternalVMObject(class_id, object_id); 213 return ReadInternalVMObject(class_id, object_id);
214 } 214 }
215 215
216 216
217 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) { 217 Dart_CObject* ApiMessageReader::ReadVMSymbol(intptr_t object_id) {
218 if (Symbols::IsVMSymbolId(object_id)) { 218 ASSERT(Symbols::IsVMSymbolId(object_id));
219 intptr_t symbol_id = object_id - kMaxPredefinedObjectIds; 219 intptr_t symbol_id = object_id - kMaxPredefinedObjectIds;
220 Dart_CObject* object; 220 Dart_CObject* object;
221 if (vm_symbol_references_ != NULL && 221 if (vm_symbol_references_ != NULL &&
222 (object = vm_symbol_references_[symbol_id]) != NULL) { 222 (object = vm_symbol_references_[symbol_id]) != NULL) {
223 return object;
224 }
225
226 if (vm_symbol_references_ == NULL) {
227 intptr_t size =
228 (sizeof(*vm_symbol_references_) * Symbols::kMaxPredefinedId);
229 vm_symbol_references_ =
230 reinterpret_cast<Dart_CObject**>(alloc_(NULL, 0, size));
231 memset(vm_symbol_references_, 0, size);
232 }
233
234 RawOneByteString* str =
235 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id));
236 intptr_t len = Smi::Value(str->ptr()->length_);
237 object = AllocateDartCObjectString(len);
238 char* p = object->value.as_string;
239 memmove(p, str->ptr()->data_, len);
240 p[len] = '\0';
241 ASSERT(vm_symbol_references_[symbol_id] == NULL);
242 vm_symbol_references_[symbol_id] = object;
243 return object; 223 return object;
244 } 224 }
245 // No other VM isolate objects are supported. 225
246 return AllocateDartCObjectNull(); 226 if (vm_symbol_references_ == NULL) {
227 intptr_t size =
228 (sizeof(*vm_symbol_references_) * Symbols::kMaxPredefinedId);
229 vm_symbol_references_ =
230 reinterpret_cast<Dart_CObject**>(alloc_(NULL, 0, size));
231 memset(vm_symbol_references_, 0, size);
232 }
233
234 RawOneByteString* str =
235 reinterpret_cast<RawOneByteString*>(Symbols::GetVMSymbol(object_id));
236 intptr_t len = Smi::Value(str->ptr()->length_);
237 object = AllocateDartCObjectString(len);
238 char* p = object->value.as_string;
239 memmove(p, str->ptr()->data_, len);
240 p[len] = '\0';
241 ASSERT(vm_symbol_references_[symbol_id] == NULL);
242 vm_symbol_references_[symbol_id] = object;
243 return object;
247 } 244 }
248 245
249 246
250 Dart_CObject* ApiMessageReader::ReadObjectRef() { 247 Dart_CObject* ApiMessageReader::ReadObjectRef() {
251 int64_t value = Read<int64_t>(); 248 int64_t value = Read<int64_t>();
252 if ((value & kSmiTagMask) == 0) { 249 if ((value & kSmiTagMask) == 0) {
253 int64_t untagged_value = value >> kSmiTagShift; 250 int64_t untagged_value = value >> kSmiTagShift;
254 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { 251 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) {
255 return AllocateDartCObjectInt32(untagged_value); 252 return AllocateDartCObjectInt32(untagged_value);
256 } else { 253 } else {
257 return AllocateDartCObjectInt64(untagged_value); 254 return AllocateDartCObjectInt64(untagged_value);
258 } 255 }
259 } 256 }
260 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); 257 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
261 if (IsVMIsolateObject(value)) { 258 if (IsVMIsolateObject(value)) {
262 intptr_t object_id = GetVMIsolateObjectId(value); 259 return ReadVMIsolateObject(value);
263 if (object_id == kNullObject) {
264 return AllocateDartCObjectNull();
265 }
266 return ReadVMSymbol(object_id);
267 } 260 }
268 if (SerializedHeaderTag::decode(value) == kObjectId) { 261 if (SerializedHeaderTag::decode(value) == kObjectId) {
269 return ReadIndexedObject(SerializedHeaderData::decode(value)); 262 return ReadIndexedObject(SerializedHeaderData::decode(value));
270 } 263 }
271 ASSERT(SerializedHeaderTag::decode(value) == kInlined); 264 ASSERT(SerializedHeaderTag::decode(value) == kInlined);
272 // Read the class header information and lookup the class. 265 // Read the class header information and lookup the class.
273 intptr_t class_header = ReadIntptrValue(); 266 intptr_t class_header = ReadIntptrValue();
274 267
275 // Reading of regular dart instances is not supported. 268 // Reading of regular dart instances is not supported.
276 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) { 269 if (SerializedHeaderData::decode(class_header) == kInstanceObjectId) {
(...skipping 10 matching lines...) Expand all
287 return value; 280 return value;
288 } 281 }
289 282
290 intptr_t tags = ReadIntptrValue(); 283 intptr_t tags = ReadIntptrValue();
291 USE(tags); 284 USE(tags);
292 285
293 return ReadInternalVMObject(class_id, object_id); 286 return ReadInternalVMObject(class_id, object_id);
294 } 287 }
295 288
296 289
290 Dart_CObject* ApiMessageReader::ReadVMIsolateObject(intptr_t value) {
291 intptr_t object_id = GetVMIsolateObjectId(value);
292 if (object_id == kNullObject) {
293 return AllocateDartCObjectNull();
294 }
295 if (object_id == kTrueValue) {
296 return AllocateDartCObjectBool(true);
297 }
298 if (object_id == kFalseValue) {
299 return AllocateDartCObjectBool(false);
300 }
301 if (Symbols::IsVMSymbolId(object_id)) {
302 return ReadVMSymbol(object_id);
303 }
304 // No other VM isolate objects are supported.
305 return AllocateDartCObjectNull();
306 }
307
308
297 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id, 309 Dart_CObject* ApiMessageReader::ReadInternalVMObject(intptr_t class_id,
298 intptr_t object_id) { 310 intptr_t object_id) {
299 switch (class_id) { 311 switch (class_id) {
300 case kClassCid: { 312 case kClassCid: {
301 return AllocateDartCObjectUnsupported(); 313 return AllocateDartCObjectUnsupported();
302 } 314 }
303 case kTypeArgumentsCid: { 315 case kTypeArgumentsCid: {
304 // TODO(sjesse): Remove this when message serialization format is 316 // TODO(sjesse): Remove this when message serialization format is
305 // updated (currently length is leaked). 317 // updated (currently length is leaked).
306 Dart_CObject* value = &type_arguments_marker; 318 Dart_CObject* value = &type_arguments_marker;
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 return value; 465 return value;
454 } 466 }
455 default: 467 default:
456 // Everything else not supported. 468 // Everything else not supported.
457 return AllocateDartCObjectUnsupported(); 469 return AllocateDartCObjectUnsupported();
458 } 470 }
459 } 471 }
460 472
461 473
462 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) { 474 Dart_CObject* ApiMessageReader::ReadIndexedObject(intptr_t object_id) {
463 if (object_id == kTrueValue) {
464 return AllocateDartCObjectBool(true);
465 }
466 if (object_id == kFalseValue) {
467 return AllocateDartCObjectBool(false);
468 }
469 if (object_id == kDynamicType || 475 if (object_id == kDynamicType ||
470 object_id == kDoubleType || 476 object_id == kDoubleType ||
471 object_id == kIntType || 477 object_id == kIntType ||
472 object_id == kBoolType || 478 object_id == kBoolType ||
473 object_id == kStringType) { 479 object_id == kStringType) {
474 // Always return dynamic type (this is only a marker). 480 // Always return dynamic type (this is only a marker).
475 return &dynamic_type_marker; 481 return &dynamic_type_marker;
476 } 482 }
477 intptr_t index = object_id - kMaxPredefinedObjectIds; 483 intptr_t index = object_id - kMaxPredefinedObjectIds;
478 ASSERT((0 <= index) && (index < backward_references_.length())); 484 ASSERT((0 <= index) && (index < backward_references_.length()));
(...skipping 19 matching lines...) Expand all
498 if ((value & kSmiTagMask) == 0) { 504 if ((value & kSmiTagMask) == 0) {
499 int64_t untagged_value = value >> kSmiTagShift; 505 int64_t untagged_value = value >> kSmiTagShift;
500 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { 506 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) {
501 return AllocateDartCObjectInt32(untagged_value); 507 return AllocateDartCObjectInt32(untagged_value);
502 } else { 508 } else {
503 return AllocateDartCObjectInt64(untagged_value); 509 return AllocateDartCObjectInt64(untagged_value);
504 } 510 }
505 } 511 }
506 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); 512 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin));
507 if (IsVMIsolateObject(value)) { 513 if (IsVMIsolateObject(value)) {
508 intptr_t object_id = GetVMIsolateObjectId(value); 514 return ReadVMIsolateObject(value);
509 if (object_id == kNullObject) {
510 return AllocateDartCObjectNull();
511 }
512 return ReadVMSymbol(object_id);
513 } 515 }
514 if (SerializedHeaderTag::decode(value) == kObjectId) { 516 if (SerializedHeaderTag::decode(value) == kObjectId) {
515 return ReadIndexedObject(SerializedHeaderData::decode(value)); 517 return ReadIndexedObject(SerializedHeaderData::decode(value));
516 } 518 }
517 ASSERT(SerializedHeaderTag::decode(value) == kInlined); 519 ASSERT(SerializedHeaderTag::decode(value) == kInlined);
518 return ReadInlinedObject(SerializedHeaderData::decode(value)); 520 return ReadInlinedObject(SerializedHeaderData::decode(value));
519 } 521 }
520 522
521 523
522 void ApiMessageReader::AddBackRef(intptr_t id, 524 void ApiMessageReader::AddBackRef(intptr_t id,
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
754 756
755 757
756 bool ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object, 758 bool ApiMessageWriter::WriteCObjectInlined(Dart_CObject* object,
757 Dart_CObject::Type type) { 759 Dart_CObject::Type type) {
758 switch (type) { 760 switch (type) {
759 case Dart_CObject::kNull: 761 case Dart_CObject::kNull:
760 WriteNullObject(); 762 WriteNullObject();
761 break; 763 break;
762 case Dart_CObject::kBool: 764 case Dart_CObject::kBool:
763 if (object->value.as_bool) { 765 if (object->value.as_bool) {
764 WriteIndexedObject(kTrueValue); 766 WriteVMIsolateObject(kTrueValue);
765 } else { 767 } else {
766 WriteIndexedObject(kFalseValue); 768 WriteVMIsolateObject(kFalseValue);
767 } 769 }
768 break; 770 break;
769 case Dart_CObject::kInt32: 771 case Dart_CObject::kInt32:
770 WriteInt32(object); 772 WriteInt32(object);
771 break; 773 break;
772 case Dart_CObject::kInt64: 774 case Dart_CObject::kInt64:
773 WriteInt64(object); 775 WriteInt64(object);
774 break; 776 break;
775 case Dart_CObject::kBigint: { 777 case Dart_CObject::kBigint: {
776 // Write out the serialization header value for this object. 778 // Write out the serialization header value for this object.
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 if (!success) { 900 if (!success) {
899 UnmarkAllCObjects(object); 901 UnmarkAllCObjects(object);
900 return false; 902 return false;
901 } 903 }
902 } 904 }
903 UnmarkAllCObjects(object); 905 UnmarkAllCObjects(object);
904 return true; 906 return true;
905 } 907 }
906 908
907 } // namespace dart 909 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_message.h ('k') | vm/dart_api_state.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698