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

Side by Side Diff: include/v8.h

Issue 77913003: 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: Created 7 years, 1 month 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') | src/isolate.h » ('J')
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 4041 matching lines...) Expand 10 before | Expand all | Expand 10 after
4052 */ 4052 */
4053 void Exit(); 4053 void Exit();
4054 4054
4055 /** 4055 /**
4056 * Disposes the isolate. The isolate must not be entered by any 4056 * Disposes the isolate. The isolate must not be entered by any
4057 * thread to be disposable. 4057 * thread to be disposable.
4058 */ 4058 */
4059 void Dispose(); 4059 void Dispose();
4060 4060
4061 /** 4061 /**
4062 * Associate embedder-specific data with the isolate 4062 * Associate embedder-specific data with the isolate. This legacy method
4063 * puts the data in the 0th slot. It will be deprecated soon.
4063 */ 4064 */
4064 V8_INLINE void SetData(void* data); 4065 V8_INLINE void SetData(void* data);
4065 4066
4066 /** 4067 /**
4067 * Retrieve embedder-specific data from the isolate. 4068 * Associate embedder-specific data with the isolate. |slot| has to be
4069 * between 0 and GetNumberOfDataSlots() - 1.
4070 */
4071 V8_INLINE void SetData(uint32_t slot, void* data);
4072
4073 /**
4074 * Retrieve embedder-specific data from the isolate. This legacy method
4075 * retrieves the data from slot 0. It will be deprecated soon.
4068 * Returns NULL if SetData has never been called. 4076 * Returns NULL if SetData has never been called.
4069 */ 4077 */
4070 V8_INLINE void* GetData(); 4078 V8_INLINE void* GetData();
4071 4079
4072 /** 4080 /**
4081 * Retrieve embedder-specific data from the isolate.
4082 * Returns NULL if SetData has never been called for the given |slot|.
4083 */
4084 V8_INLINE void* GetData(uint32_t slot);
4085
4086 /**
4087 * Returns the maximum number of available embedder data slots. Valid slots
4088 * are in the range of 0 - GetNumberOfDataSlots() - 1.
4089 */
4090 V8_INLINE static uint32_t GetNumberOfDataSlots();
4091
4092 /**
4073 * Get statistics about the heap memory usage. 4093 * Get statistics about the heap memory usage.
4074 */ 4094 */
4075 void GetHeapStatistics(HeapStatistics* heap_statistics); 4095 void GetHeapStatistics(HeapStatistics* heap_statistics);
4076 4096
4077 /** 4097 /**
4078 * Adjusts the amount of registered external memory. Used to give V8 an 4098 * Adjusts the amount of registered external memory. Used to give V8 an
4079 * indication of the amount of externally allocated memory that is kept alive 4099 * indication of the amount of externally allocated memory that is kept alive
4080 * by JavaScript objects. V8 uses this to decide when to perform global 4100 * by JavaScript objects. V8 uses this to decide when to perform global
4081 * garbage collections. Registering externally allocated memory will trigger 4101 * garbage collections. Registering externally allocated memory will trigger
4082 * global garbage collections more often than it would otherwise in an attempt 4102 * global garbage collections more often than it would otherwise in an attempt
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after
5447 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; 5467 static const int kJSObjectHeaderSize = 3 * kApiPointerSize;
5448 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; 5468 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize;
5449 static const int kContextHeaderSize = 2 * kApiPointerSize; 5469 static const int kContextHeaderSize = 2 * kApiPointerSize;
5450 static const int kContextEmbedderDataIndex = 65; 5470 static const int kContextEmbedderDataIndex = 65;
5451 static const int kFullStringRepresentationMask = 0x07; 5471 static const int kFullStringRepresentationMask = 0x07;
5452 static const int kStringEncodingMask = 0x4; 5472 static const int kStringEncodingMask = 0x4;
5453 static const int kExternalTwoByteRepresentationTag = 0x02; 5473 static const int kExternalTwoByteRepresentationTag = 0x02;
5454 static const int kExternalAsciiRepresentationTag = 0x06; 5474 static const int kExternalAsciiRepresentationTag = 0x06;
5455 5475
5456 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; 5476 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize;
5457 static const int kIsolateRootsOffset = 3 * kApiPointerSize; 5477 static const int kIsolateRootsOffset = 6 * kApiPointerSize;
5458 static const int kUndefinedValueRootIndex = 5; 5478 static const int kUndefinedValueRootIndex = 5;
5459 static const int kNullValueRootIndex = 7; 5479 static const int kNullValueRootIndex = 7;
5460 static const int kTrueValueRootIndex = 8; 5480 static const int kTrueValueRootIndex = 8;
5461 static const int kFalseValueRootIndex = 9; 5481 static const int kFalseValueRootIndex = 9;
5462 static const int kEmptyStringRootIndex = 134; 5482 static const int kEmptyStringRootIndex = 134;
5463 5483
5464 static const int kNodeClassIdOffset = 1 * kApiPointerSize; 5484 static const int kNodeClassIdOffset = 1 * kApiPointerSize;
5465 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; 5485 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
5466 static const int kNodeStateMask = 0xf; 5486 static const int kNodeStateMask = 0xf;
5467 static const int kNodeStateIsWeakValue = 2; 5487 static const int kNodeStateIsWeakValue = 2;
5468 static const int kNodeStateIsPendingValue = 3; 5488 static const int kNodeStateIsPendingValue = 3;
5469 static const int kNodeStateIsNearDeathValue = 4; 5489 static const int kNodeStateIsNearDeathValue = 4;
5470 static const int kNodeIsIndependentShift = 4; 5490 static const int kNodeIsIndependentShift = 4;
5471 static const int kNodeIsPartiallyDependentShift = 5; 5491 static const int kNodeIsPartiallyDependentShift = 5;
5472 5492
5473 static const int kJSObjectType = 0xb2; 5493 static const int kJSObjectType = 0xb2;
5474 static const int kFirstNonstringType = 0x80; 5494 static const int kFirstNonstringType = 0x80;
5475 static const int kOddballType = 0x83; 5495 static const int kOddballType = 0x83;
5476 static const int kForeignType = 0x87; 5496 static const int kForeignType = 0x87;
5477 5497
5478 static const int kUndefinedOddballKind = 5; 5498 static const int kUndefinedOddballKind = 5;
5479 static const int kNullOddballKind = 3; 5499 static const int kNullOddballKind = 3;
5480 5500
5501 static const uint32_t kNumIsolateDataSlots = 4;
5502
5481 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); 5503 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
5482 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { 5504 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
5483 #ifdef V8_ENABLE_CHECKS 5505 #ifdef V8_ENABLE_CHECKS
5484 CheckInitializedImpl(isolate); 5506 CheckInitializedImpl(isolate);
5485 #endif 5507 #endif
5486 } 5508 }
5487 5509
5488 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { 5510 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) {
5489 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == 5511 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) ==
5490 kHeapObjectTag); 5512 kHeapObjectTag);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
5534 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; 5556 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5535 return *addr & kNodeStateMask; 5557 return *addr & kNodeStateMask;
5536 } 5558 }
5537 5559
5538 V8_INLINE static void UpdateNodeState(internal::Object** obj, 5560 V8_INLINE static void UpdateNodeState(internal::Object** obj,
5539 uint8_t value) { 5561 uint8_t value) {
5540 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; 5562 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
5541 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); 5563 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
5542 } 5564 }
5543 5565
5544 V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, void* data) { 5566 V8_INLINE static void SetEmbedderData(v8::Isolate *isolate,
Paweł Hajdan Jr. 2013/12/18 12:49:55 Shouldn't there be V8_DEPRECATED SetEmbedderData(v
5545 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 5567 uint32_t slot,
5546 kIsolateEmbedderDataOffset; 5568 void *data) {
5569 uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) +
5570 kIsolateEmbedderDataOffset + slot * kApiPointerSize;
5547 *reinterpret_cast<void**>(addr) = data; 5571 *reinterpret_cast<void**>(addr) = data;
5548 } 5572 }
5549 5573
5550 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate) { 5574 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate, uint32_t slot) {
5551 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + 5575 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) +
5552 kIsolateEmbedderDataOffset; 5576 kIsolateEmbedderDataOffset + slot * kApiPointerSize;
5553 return *reinterpret_cast<void**>(addr); 5577 return *reinterpret_cast<void**>(addr);
5554 } 5578 }
5555 5579
5556 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, 5580 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate,
5557 int index) { 5581 int index) {
5558 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; 5582 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset;
5559 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); 5583 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize);
5560 } 5584 }
5561 5585
5562 template <typename T> V8_INLINE static T ReadField(Object* ptr, int offset) { 5586 template <typename T> V8_INLINE static T ReadField(Object* ptr, int offset) {
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after
6468 typedef internal::Object* S; 6492 typedef internal::Object* S;
6469 typedef internal::Internals I; 6493 typedef internal::Internals I;
6470 I::CheckInitialized(isolate); 6494 I::CheckInitialized(isolate);
6471 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); 6495 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex);
6472 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); 6496 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot));
6473 } 6497 }
6474 6498
6475 6499
6476 void Isolate::SetData(void* data) { 6500 void Isolate::SetData(void* data) {
6477 typedef internal::Internals I; 6501 typedef internal::Internals I;
6478 I::SetEmbedderData(this, data); 6502 I::SetEmbedderData(this, 0, data);
6479 } 6503 }
6480 6504
6481 6505
6482 void* Isolate::GetData() { 6506 void* Isolate::GetData() {
6483 typedef internal::Internals I; 6507 typedef internal::Internals I;
6484 return I::GetEmbedderData(this); 6508 return I::GetEmbedderData(this, 0);
6485 } 6509 }
6486 6510
6487 6511
6512 void Isolate::SetData(uint32_t slot, void* data) {
6513 typedef internal::Internals I;
6514 I::SetEmbedderData(this, slot, data);
6515 }
6516
6517
6518 void* Isolate::GetData(uint32_t slot) {
6519 typedef internal::Internals I;
6520 return I::GetEmbedderData(this, slot);
6521 }
6522
6523
6524 uint32_t Isolate::GetNumberOfDataSlots() {
6525 typedef internal::Internals I;
6526 return I::kNumIsolateDataSlots;
6527 }
6528
6529
6488 template<typename T> 6530 template<typename T>
6489 void Isolate::SetObjectGroupId(const Persistent<T>& object, 6531 void Isolate::SetObjectGroupId(const Persistent<T>& object,
6490 UniqueId id) { 6532 UniqueId id) {
6491 TYPE_CHECK(Value, T); 6533 TYPE_CHECK(Value, T);
6492 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); 6534 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
6493 } 6535 }
6494 6536
6495 6537
6496 template<typename T> 6538 template<typename T>
6497 void Isolate::SetReferenceFromGroup(UniqueId id, 6539 void Isolate::SetReferenceFromGroup(UniqueId id,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6549 */ 6591 */
6550 6592
6551 6593
6552 } // namespace v8 6594 } // namespace v8
6553 6595
6554 6596
6555 #undef TYPE_CHECK 6597 #undef TYPE_CHECK
6556 6598
6557 6599
6558 #endif // V8_H_ 6600 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/d8.cc » ('j') | src/isolate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698