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

Side by Side Diff: include/v8.h

Issue 78453002: Reland r17907 - Make it possible to add more than one piece of embedder data to isolates" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 7 years 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 | « no previous file | src/d8.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 4036 matching lines...) Expand 10 before | Expand all | Expand 10 after
4047 */ 4047 */
4048 void Exit(); 4048 void Exit();
4049 4049
4050 /** 4050 /**
4051 * Disposes the isolate. The isolate must not be entered by any 4051 * Disposes the isolate. The isolate must not be entered by any
4052 * thread to be disposable. 4052 * thread to be disposable.
4053 */ 4053 */
4054 void Dispose(); 4054 void Dispose();
4055 4055
4056 /** 4056 /**
4057 * Associate embedder-specific data with the isolate 4057 * Associate embedder-specific data with the isolate. This legacy method
4058 * puts the data in the 0th slot. It will be deprecated soon.
4058 */ 4059 */
4059 V8_INLINE void SetData(void* data); 4060 V8_INLINE void SetData(void* data);
4060 4061
4061 /** 4062 /**
4062 * Retrieve embedder-specific data from the isolate. 4063 * Associate embedder-specific data with the isolate. |slot| has to be
4064 * between 0 and GetNumberOfDataSlots() - 1.
4065 */
4066 V8_INLINE void SetData(uint32_t slot, void* data);
4067
4068 /**
4069 * Retrieve embedder-specific data from the isolate. This legacy method
4070 * retrieves the data from slot 0. It will be deprecated soon.
4063 * Returns NULL if SetData has never been called. 4071 * Returns NULL if SetData has never been called.
4064 */ 4072 */
4065 V8_INLINE void* GetData(); 4073 V8_INLINE void* GetData();
4066 4074
4067 /** 4075 /**
4076 * Retrieve embedder-specific data from the isolate.
4077 * Returns NULL if SetData has never been called for the given |slot|.
4078 */
4079 V8_INLINE void* GetData(uint32_t slot);
4080
4081 /**
4082 * Returns the maximum number of available embedder data slots. Valid slots
4083 * are in the range of 0 - GetNumberOfDataSlots() - 1.
4084 */
4085 V8_INLINE static uint32_t GetNumberOfDataSlots();
4086
4087 /**
4068 * Get statistics about the heap memory usage. 4088 * Get statistics about the heap memory usage.
4069 */ 4089 */
4070 void GetHeapStatistics(HeapStatistics* heap_statistics); 4090 void GetHeapStatistics(HeapStatistics* heap_statistics);
4071 4091
4072 /** 4092 /**
4073 * Adjusts the amount of registered external memory. Used to give V8 an 4093 * Adjusts the amount of registered external memory. Used to give V8 an
4074 * indication of the amount of externally allocated memory that is kept alive 4094 * indication of the amount of externally allocated memory that is kept alive
4075 * by JavaScript objects. V8 uses this to decide when to perform global 4095 * by JavaScript objects. V8 uses this to decide when to perform global
4076 * garbage collections. Registering externally allocated memory will trigger 4096 * garbage collections. Registering externally allocated memory will trigger
4077 * global garbage collections more often than it would otherwise in an attempt 4097 * global garbage collections more often than it would otherwise in an attempt
(...skipping 1363 matching lines...) Expand 10 before | Expand all | Expand 10 after
5441 static const int kForeignAddressOffset = kApiPointerSize; 5461 static const int kForeignAddressOffset = kApiPointerSize;
5442 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 5462 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
5443 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; 5463 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
5444 static const int kContextHeaderSize = 2 * kApiPointerSize; 5464 static const int kContextHeaderSize = 2 * kApiPointerSize;
5445 static const int kContextEmbedderDataIndex = 65; 5465 static const int kContextEmbedderDataIndex = 65;
5446 static const int kFullStringRepresentationMask = 0x07; 5466 static const int kFullStringRepresentationMask = 0x07;
5447 static const int kStringEncodingMask = 0x4; 5467 static const int kStringEncodingMask = 0x4;
5448 static const int kExternalTwoByteRepresentationTag = 0x02; 5468 static const int kExternalTwoByteRepresentationTag = 0x02;
5449 static const int kExternalAsciiRepresentationTag = 0x06; 5469 static const int kExternalAsciiRepresentationTag = 0x06;
5450 5470
5451 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 5471 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
5452 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 5472 static const int kIsolateRootsOffset = 5 * kApiPointerSize;
5453 static const int kUndefinedValueRootIndex = 5; 5473 static const int kUndefinedValueRootIndex = 5;
5454 static const int kNullValueRootIndex = 7; 5474 static const int kNullValueRootIndex = 7;
5455 static const int kTrueValueRootIndex = 8; 5475 static const int kTrueValueRootIndex = 8;
5456 static const int kFalseValueRootIndex = 9; 5476 static const int kFalseValueRootIndex = 9;
5457 static const int kEmptyStringRootIndex = 134; 5477 static const int kEmptyStringRootIndex = 134;
5458 5478
5459 static const int kNodeClassIdOffset = 1 * kApiPointerSize; 5479 static const int kNodeClassIdOffset = 1 * kApiPointerSize;
5460 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; 5480 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
5461 static const int kNodeStateMask = 0xf; 5481 static const int kNodeStateMask = 0xf;
5462 static const int kNodeStateIsWeakValue = 2; 5482 static const int kNodeStateIsWeakValue = 2;
5463 static const int kNodeStateIsPendingValue = 3; 5483 static const int kNodeStateIsPendingValue = 3;
5464 static const int kNodeStateIsNearDeathValue = 4; 5484 static const int kNodeStateIsNearDeathValue = 4;
5465 static const int kNodeIsIndependentShift = 4; 5485 static const int kNodeIsIndependentShift = 4;
5466 static const int kNodeIsPartiallyDependentShift = 5; 5486 static const int kNodeIsPartiallyDependentShift = 5;
5467 5487
5468 static const int kJSObjectType = 0xb2; 5488 static const int kJSObjectType = 0xb2;
5469 static const int kFirstNonstringType = 0x80; 5489 static const int kFirstNonstringType = 0x80;
5470 static const int kOddballType = 0x83; 5490 static const int kOddballType = 0x83;
5471 static const int kForeignType = 0x87; 5491 static const int kForeignType = 0x87;
5472 5492
5473 static const int kUndefinedOddballKind = 5; 5493 static const int kUndefinedOddballKind = 5;
5474 static const int kNullOddballKind = 3; 5494 static const int kNullOddballKind = 3;
5475 5495
5496 static const uint32_t kNumIsolateDataSlots = 4;
5497
5476 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); 5498 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
5477 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { 5499 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
5478 #ifdef V8_ENABLE_CHECKS 5500 #ifdef V8_ENABLE_CHECKS
5479 CheckInitializedImpl(isolate); 5501 CheckInitializedImpl(isolate);
5480 #endif 5502 #endif
5481 } 5503 }
5482 5504
5483 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { 5505 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) {
5484 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == 5506 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
5485 kHeapObjectTag); 5507 kHeapObjectTag);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5529 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; 5551 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5530 return *addr & kNodeStateMask; 5552 return *addr & kNodeStateMask;
5531 } 5553 }
5532 5554
5533 V8_INLINE static void UpdateNodeState(internal::Object** obj, 5555 V8_INLINE static void UpdateNodeState(internal::Object** obj,
5534 uint8_t value) { 5556 uint8_t value) {
5535 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; 5557 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5536 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); 5558 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
5537 } 5559 }
5538 5560
5539 V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, void* data) { 5561 V8_INLINE static void SetEmbedderData(v8::Isolate *isolate,
5540 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 5562 uint32_t slot,
5541 kIsolateEmbedderDataOffset; 5563 void *data) {
5564 uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) +
5565 kIsolateEmbedderDataOffset + slot * kApiPointerSize;
5542 *reinterpret_cast<void**>(addr) = data; 5566 *reinterpret_cast<void**>(addr) = data;
5543 } 5567 }
5544 5568
5545 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate) { 5569 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate, uint32_t slot) {
5546 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 5570 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
5547 kIsolateEmbedderDataOffset; 5571 kIsolateEmbedderDataOffset + slot * kApiPointerSize;
5548 return *reinterpret_cast<void**>(addr); 5572 return *reinterpret_cast<void**>(addr);
5549 } 5573 }
5550 5574
5551 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, 5575 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
5552 int index) { 5576 int index) {
5553 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; 5577 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
5554 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); 5578 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
5555 } 5579 }
5556 5580
5557 template <typename T> V8_INLINE static T ReadField(Object* ptr, int offset) { 5581 template <typename T> V8_INLINE static T ReadField(Object* ptr, int offset) {
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
6463 typedef internal::Object* S; 6487 typedef internal::Object* S;
6464 typedef internal::Internals I; 6488 typedef internal::Internals I;
6465 I::CheckInitialized(isolate); 6489 I::CheckInitialized(isolate);
6466 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); 6490 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
6467 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); 6491 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
6468 } 6492 }
6469 6493
6470 6494
6471 void Isolate::SetData(void* data) { 6495 void Isolate::SetData(void* data) {
6472 typedef internal::Internals I; 6496 typedef internal::Internals I;
6473 I::SetEmbedderData(this, data); 6497 I::SetEmbedderData(this, 0, data);
6474 } 6498 }
6475 6499
6476 6500
6477 void* Isolate::GetData() { 6501 void* Isolate::GetData() {
6478 typedef internal::Internals I; 6502 typedef internal::Internals I;
6479 return I::GetEmbedderData(this); 6503 return I::GetEmbedderData(this, 0);
6480 } 6504 }
6481 6505
6482 6506
6507 void Isolate::SetData(uint32_t slot, void* data) {
6508 typedef internal::Internals I;
6509 I::SetEmbedderData(this, slot, data);
6510 }
6511
6512
6513 void* Isolate::GetData(uint32_t slot) {
6514 typedef internal::Internals I;
6515 return I::GetEmbedderData(this, slot);
6516 }
6517
6518
6519 uint32_t Isolate::GetNumberOfDataSlots() {
6520 typedef internal::Internals I;
6521 return I::kNumIsolateDataSlots;
6522 }
6523
6524
6483 template<typename T> 6525 template<typename T>
6484 void Isolate::SetObjectGroupId(const Persistent<T>& object, 6526 void Isolate::SetObjectGroupId(const Persistent<T>& object,
6485 UniqueId id) { 6527 UniqueId id) {
6486 TYPE_CHECK(Value, T); 6528 TYPE_CHECK(Value, T);
6487 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); 6529 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
6488 } 6530 }
6489 6531
6490 6532
6491 template<typename T> 6533 template<typename T>
6492 void Isolate::SetReferenceFromGroup(UniqueId id, 6534 void Isolate::SetReferenceFromGroup(UniqueId id,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6544 */ 6586 */
6545 6587
6546 6588
6547 } // namespace v8 6589 } // namespace v8
6548 6590
6549 6591
6550 #undef TYPE_CHECK 6592 #undef TYPE_CHECK
6551 6593
6552 6594
6553 #endif // V8_H_ 6595 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/d8.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698