Remove all stuff marked as V8_DEPRECATED.

R=jochen@chromium.org, mstarzinger@chromium.org, yurys@chromium.org

Review URL: https://codereview.chromium.org/99193002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@18333 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent dc25e0c4
...@@ -475,21 +475,6 @@ class V8_EXPORT HeapProfiler { ...@@ -475,21 +475,6 @@ class V8_EXPORT HeapProfiler {
*/ */
void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info); void SetRetainedObjectInfo(UniqueId id, RetainedObjectInfo* info);
/**
* Starts recording JS allocations immediately as they arrive and tracking of
* heap objects population statistics.
*/
V8_DEPRECATED("Use StartTrackingHeapObjects instead",
void StartRecordingHeapAllocations());
/**
* Stops recording JS allocations and tracking of heap objects population
* statistics, cleans all collected heap objects population statistics data.
*/
V8_DEPRECATED("Use StopTrackingHeapObjects instead",
void StopRecordingHeapAllocations());
private: private:
HeapProfiler(); HeapProfiler();
~HeapProfiler(); ~HeapProfiler();
......
This diff is collapsed.
...@@ -246,16 +246,15 @@ AllocationTracker::UnresolvedLocation::UnresolvedLocation( ...@@ -246,16 +246,15 @@ AllocationTracker::UnresolvedLocation::UnresolvedLocation(
info_(info) { info_(info) {
script_ = Handle<Script>::cast( script_ = Handle<Script>::cast(
script->GetIsolate()->global_handles()->Create(script)); script->GetIsolate()->global_handles()->Create(script));
GlobalHandles::MakeWeak( GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
reinterpret_cast<Object**>(script_.location()), this,
this, &HandleWeakScript); &HandleWeakScript);
} }
AllocationTracker::UnresolvedLocation::~UnresolvedLocation() { AllocationTracker::UnresolvedLocation::~UnresolvedLocation() {
if (!script_.is_null()) { if (!script_.is_null()) {
script_->GetIsolate()->global_handles()->Destroy( GlobalHandles::Destroy(reinterpret_cast<Object**>(script_.location()));
reinterpret_cast<Object**>(script_.location()));
} }
} }
...@@ -268,12 +267,11 @@ void AllocationTracker::UnresolvedLocation::Resolve() { ...@@ -268,12 +267,11 @@ void AllocationTracker::UnresolvedLocation::Resolve() {
void AllocationTracker::UnresolvedLocation::HandleWeakScript( void AllocationTracker::UnresolvedLocation::HandleWeakScript(
v8::Isolate* isolate, const v8::WeakCallbackData<v8::Value, void>& data) {
v8::Persistent<v8::Value>* obj, UnresolvedLocation* loc =
void* data) { reinterpret_cast<UnresolvedLocation*>(data.GetParameter());
UnresolvedLocation* location = reinterpret_cast<UnresolvedLocation*>(data); GlobalHandles::Destroy(reinterpret_cast<Object**>(loc->script_.location()));
location->script_ = Handle<Script>::null(); loc->script_ = Handle<Script>::null();
obj->Reset();
} }
......
...@@ -112,9 +112,9 @@ class AllocationTracker { ...@@ -112,9 +112,9 @@ class AllocationTracker {
void Resolve(); void Resolve();
private: private:
static void HandleWeakScript(v8::Isolate* isolate, static void HandleWeakScript(
v8::Persistent<v8::Value>* obj, const v8::WeakCallbackData<v8::Value, void>& data);
void* data);
Handle<Script> script_; Handle<Script> script_;
int start_position_; int start_position_;
FunctionInfo* info_; FunctionInfo* info_;
......
This diff is collapsed.
...@@ -646,11 +646,10 @@ void ScriptCache::Add(Handle<Script> script) { ...@@ -646,11 +646,10 @@ void ScriptCache::Add(Handle<Script> script) {
// Globalize the script object, make it weak and use the location of the // Globalize the script object, make it weak and use the location of the
// global handle as the value in the hash map. // global handle as the value in the hash map.
Handle<Script> script_ = Handle<Script> script_ =
Handle<Script>::cast( Handle<Script>::cast(global_handles->Create(*script));
(global_handles->Create(*script))); GlobalHandles::MakeWeak(reinterpret_cast<Object**>(script_.location()),
global_handles->MakeWeak(reinterpret_cast<Object**>(script_.location()), this,
this, ScriptCache::HandleWeakScript);
ScriptCache::HandleWeakScript);
entry->value = script_.location(); entry->value = script_.location();
} }
...@@ -680,36 +679,37 @@ void ScriptCache::ProcessCollectedScripts() { ...@@ -680,36 +679,37 @@ void ScriptCache::ProcessCollectedScripts() {
void ScriptCache::Clear() { void ScriptCache::Clear() {
GlobalHandles* global_handles = isolate_->global_handles();
// Iterate the script cache to get rid of all the weak handles. // Iterate the script cache to get rid of all the weak handles.
for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) { for (HashMap::Entry* entry = Start(); entry != NULL; entry = Next(entry)) {
ASSERT(entry != NULL); ASSERT(entry != NULL);
Object** location = reinterpret_cast<Object**>(entry->value); Object** location = reinterpret_cast<Object**>(entry->value);
ASSERT((*location)->IsScript()); ASSERT((*location)->IsScript());
global_handles->ClearWeakness(location); GlobalHandles::ClearWeakness(location);
global_handles->Destroy(location); GlobalHandles::Destroy(location);
} }
// Clear the content of the hash map. // Clear the content of the hash map.
HashMap::Clear(); HashMap::Clear();
} }
void ScriptCache::HandleWeakScript(v8::Isolate* isolate, void ScriptCache::HandleWeakScript(
v8::Persistent<v8::Value>* obj, const v8::WeakCallbackData<v8::Value, void>& data) {
void* data) { // Retrieve the script identifier.
ScriptCache* script_cache = reinterpret_cast<ScriptCache*>(data); Handle<Object> object = Utils::OpenHandle(*data.GetValue());
// Find the location of the global handle. int id = Handle<Script>::cast(object)->id()->value();
Script** location = void* key = reinterpret_cast<void*>(id);
reinterpret_cast<Script**>(Utils::OpenPersistent(*obj).location()); uint32_t hash = Hash(id);
ASSERT((*location)->IsScript());
// Remove the entry from the cache. // Remove the corresponding entry from the cache.
int id = (*location)->id()->value(); ScriptCache* script_cache =
script_cache->Remove(reinterpret_cast<void*>(id), Hash(id)); reinterpret_cast<ScriptCache*>(data.GetParameter());
HashMap::Entry* entry = script_cache->Lookup(key, hash, false);
Object** location = reinterpret_cast<Object**>(entry->value);
script_cache->Remove(key, hash);
script_cache->collected_scripts_.Add(id); script_cache->collected_scripts_.Add(id);
// Clear the weak handle. // Clear the weak handle.
obj->Reset(); GlobalHandles::Destroy(location);
} }
...@@ -728,11 +728,11 @@ void Debug::SetUp(bool create_heap_objects) { ...@@ -728,11 +728,11 @@ void Debug::SetUp(bool create_heap_objects) {
} }
void Debug::HandleWeakDebugInfo(v8::Isolate* isolate, void Debug::HandleWeakDebugInfo(
v8::Persistent<v8::Value>* obj, const v8::WeakCallbackData<v8::Value, void>& data) {
void* data) { Debug* debug = reinterpret_cast<Isolate*>(data.GetIsolate())->debug();
Debug* debug = reinterpret_cast<Isolate*>(isolate)->debug(); DebugInfoListNode* node =
DebugInfoListNode* node = reinterpret_cast<DebugInfoListNode*>(data); reinterpret_cast<DebugInfoListNode*>(data.GetParameter());
// We need to clear all breakpoints associated with the function to restore // We need to clear all breakpoints associated with the function to restore
// original code and avoid patching the code twice later because // original code and avoid patching the code twice later because
// the function will live in the heap until next gc, and can be found by // the function will live in the heap until next gc, and can be found by
...@@ -741,29 +741,27 @@ void Debug::HandleWeakDebugInfo(v8::Isolate* isolate, ...@@ -741,29 +741,27 @@ void Debug::HandleWeakDebugInfo(v8::Isolate* isolate,
it.ClearAllDebugBreak(); it.ClearAllDebugBreak();
debug->RemoveDebugInfo(node->debug_info()); debug->RemoveDebugInfo(node->debug_info());
#ifdef DEBUG #ifdef DEBUG
node = debug->debug_info_list_; for (DebugInfoListNode* n = debug->debug_info_list_;
while (node != NULL) { n != NULL;
ASSERT(node != reinterpret_cast<DebugInfoListNode*>(data)); n = n->next()) {
node = node->next(); ASSERT(n != node);
} }
#endif #endif
} }
DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) { DebugInfoListNode::DebugInfoListNode(DebugInfo* debug_info): next_(NULL) {
GlobalHandles* global_handles = debug_info->GetIsolate()->global_handles();
// Globalize the request debug info object and make it weak. // Globalize the request debug info object and make it weak.
debug_info_ = Handle<DebugInfo>::cast( GlobalHandles* global_handles = debug_info->GetIsolate()->global_handles();
(global_handles->Create(debug_info))); debug_info_ = Handle<DebugInfo>::cast(global_handles->Create(debug_info));
global_handles->MakeWeak(reinterpret_cast<Object**>(debug_info_.location()), GlobalHandles::MakeWeak(reinterpret_cast<Object**>(debug_info_.location()),
this, this,
Debug::HandleWeakDebugInfo); Debug::HandleWeakDebugInfo);
} }
DebugInfoListNode::~DebugInfoListNode() { DebugInfoListNode::~DebugInfoListNode() {
debug_info_->GetIsolate()->global_handles()->Destroy( GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_info_.location()));
reinterpret_cast<Object**>(debug_info_.location()));
} }
...@@ -921,8 +919,7 @@ void Debug::Unload() { ...@@ -921,8 +919,7 @@ void Debug::Unload() {
DestroyScriptCache(); DestroyScriptCache();
// Clear debugger context global handle. // Clear debugger context global handle.
isolate_->global_handles()->Destroy( GlobalHandles::Destroy(reinterpret_cast<Object**>(debug_context_.location()));
reinterpret_cast<Object**>(debug_context_.location()));
debug_context_ = Handle<Context>(); debug_context_ = Handle<Context>();
} }
...@@ -3249,12 +3246,12 @@ void Debugger::SetEventListener(Handle<Object> callback, ...@@ -3249,12 +3246,12 @@ void Debugger::SetEventListener(Handle<Object> callback,
// Clear the global handles for the event listener and the event listener data // Clear the global handles for the event listener and the event listener data
// object. // object.
if (!event_listener_.is_null()) { if (!event_listener_.is_null()) {
global_handles->Destroy( GlobalHandles::Destroy(
reinterpret_cast<Object**>(event_listener_.location())); reinterpret_cast<Object**>(event_listener_.location()));
event_listener_ = Handle<Object>(); event_listener_ = Handle<Object>();
} }
if (!event_listener_data_.is_null()) { if (!event_listener_data_.is_null()) {
global_handles->Destroy( GlobalHandles::Destroy(
reinterpret_cast<Object**>(event_listener_data_.location())); reinterpret_cast<Object**>(event_listener_data_.location()));
event_listener_data_ = Handle<Object>(); event_listener_data_ = Handle<Object>();
} }
......
...@@ -201,9 +201,8 @@ class ScriptCache : private HashMap { ...@@ -201,9 +201,8 @@ class ScriptCache : private HashMap {
void Clear(); void Clear();
// Weak handle callback for scripts in the cache. // Weak handle callback for scripts in the cache.
static void HandleWeakScript(v8::Isolate* isolate, static void HandleWeakScript(
v8::Persistent<v8::Value>* obj, const v8::WeakCallbackData<v8::Value, void>& data);
void* data);
Isolate* isolate_; Isolate* isolate_;
// List used during GC to temporarily store id's of collected scripts. // List used during GC to temporarily store id's of collected scripts.
...@@ -403,9 +402,8 @@ class Debug { ...@@ -403,9 +402,8 @@ class Debug {
static const int kEstimatedNofBreakPointsInFunction = 16; static const int kEstimatedNofBreakPointsInFunction = 16;
// Passed to MakeWeak. // Passed to MakeWeak.
static void HandleWeakDebugInfo(v8::Isolate* isolate, static void HandleWeakDebugInfo(
v8::Persistent<v8::Value>* obj, const v8::WeakCallbackData<v8::Value, void>& data);
void* data);
friend class Debugger; friend class Debugger;
friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc friend Handle<FixedArray> GetDebuggedFunctions(); // In test-debug.cc
......
...@@ -169,13 +169,6 @@ class GlobalHandles::Node { ...@@ -169,13 +169,6 @@ class GlobalHandles::Node {
flags_ = IsInNewSpaceList::update(flags_, v); flags_ = IsInNewSpaceList::update(flags_, v);
} }
bool is_revivable_callback() {
return IsRevivableCallback::decode(flags_);
}
void set_revivable_callback(bool v) {
flags_ = IsRevivableCallback::update(flags_, v);
}
bool IsNearDeath() const { bool IsNearDeath() const {
// Check for PENDING to ensure correct answer when processing callbacks. // Check for PENDING to ensure correct answer when processing callbacks.
return state() == PENDING || state() == NEAR_DEATH; return state() == PENDING || state() == NEAR_DEATH;
...@@ -234,21 +227,12 @@ class GlobalHandles::Node { ...@@ -234,21 +227,12 @@ class GlobalHandles::Node {
parameter_or_next_free_.next_free = value; parameter_or_next_free_.next_free = value;
} }
void MakeWeak(void* parameter, void MakeWeak(void* parameter, WeakCallback weak_callback) {
WeakCallback weak_callback, ASSERT(weak_callback != NULL);
RevivableCallback revivable_callback) {
ASSERT((weak_callback == NULL) != (revivable_callback == NULL));
ASSERT(state() != FREE); ASSERT(state() != FREE);
set_state(WEAK); set_state(WEAK);
set_parameter(parameter); set_parameter(parameter);
if (weak_callback != NULL) { weak_callback_ = weak_callback;
weak_callback_ = weak_callback;
set_revivable_callback(false);
} else {
weak_callback_ =
reinterpret_cast<WeakCallback>(revivable_callback);
set_revivable_callback(true);
}
} }
void ClearWeakness() { void ClearWeakness() {
...@@ -278,20 +262,12 @@ class GlobalHandles::Node { ...@@ -278,20 +262,12 @@ class GlobalHandles::Node {
// Leaving V8. // Leaving V8.
VMState<EXTERNAL> state(isolate); VMState<EXTERNAL> state(isolate);
HandleScope handle_scope(isolate); HandleScope handle_scope(isolate);
if (is_revivable_callback()) { Handle<Object> handle(*object, isolate);
RevivableCallback revivable = v8::WeakCallbackData<v8::Value, void> data(
reinterpret_cast<RevivableCallback>(weak_callback_); reinterpret_cast<v8::Isolate*>(isolate),
revivable(reinterpret_cast<v8::Isolate*>(isolate), v8::Utils::ToLocal(handle),
reinterpret_cast<Persistent<Value>*>(&object), par);
par); weak_callback_(data);
} else {
Handle<Object> handle(*object, isolate);
v8::WeakCallbackData<v8::Value, void> data(
reinterpret_cast<v8::Isolate*>(isolate),
v8::Utils::ToLocal(handle),
par);
weak_callback_(data);
}
} }
// Absence of explicit cleanup or revival of weak handle // Absence of explicit cleanup or revival of weak handle
// in most of the cases would lead to memory leak. // in most of the cases would lead to memory leak.
...@@ -325,7 +301,6 @@ class GlobalHandles::Node { ...@@ -325,7 +301,6 @@ class GlobalHandles::Node {
class IsIndependent: public BitField<bool, 4, 1> {}; class IsIndependent: public BitField<bool, 4, 1> {};
class IsPartiallyDependent: public BitField<bool, 5, 1> {}; class IsPartiallyDependent: public BitField<bool, 5, 1> {};
class IsInNewSpaceList: public BitField<bool, 6, 1> {}; class IsInNewSpaceList: public BitField<bool, 6, 1> {};
class IsRevivableCallback: public BitField<bool, 7, 1> {};
uint8_t flags_; uint8_t flags_;
...@@ -522,10 +497,8 @@ void GlobalHandles::Destroy(Object** location) { ...@@ -522,10 +497,8 @@ void GlobalHandles::Destroy(Object** location) {
void GlobalHandles::MakeWeak(Object** location, void GlobalHandles::MakeWeak(Object** location,
void* parameter, void* parameter,
WeakCallback weak_callback, WeakCallback weak_callback) {
RevivableCallback revivable_callback) { Node::FromLocation(location)->MakeWeak(parameter, weak_callback);
Node::FromLocation(location)->MakeWeak(
parameter, weak_callback, revivable_callback);
} }
......
...@@ -135,7 +135,6 @@ class GlobalHandles { ...@@ -135,7 +135,6 @@ class GlobalHandles {
static void Destroy(Object** location); static void Destroy(Object** location);
typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback; typedef WeakCallbackData<v8::Value, void>::Callback WeakCallback;
typedef WeakReferenceCallbacks<v8::Value, void>::Revivable RevivableCallback;
// Make the global handle weak and set the callback parameter for the // Make the global handle weak and set the callback parameter for the
// handle. When the garbage collector recognizes that only weak global // handle. When the garbage collector recognizes that only weak global
...@@ -145,14 +144,7 @@ class GlobalHandles { ...@@ -145,14 +144,7 @@ class GlobalHandles {
// reason is that Smi::FromInt(0) does not change during garage collection. // reason is that Smi::FromInt(0) does not change during garage collection.
static void MakeWeak(Object** location, static void MakeWeak(Object** location,
void* parameter, void* parameter,
WeakCallback weak_callback, WeakCallback weak_callback);
RevivableCallback revivable_callback);
static inline void MakeWeak(Object** location,
void* parameter,
RevivableCallback revivable_callback) {
MakeWeak(location, parameter, NULL, revivable_callback);
}
void RecordStats(HeapStats* stats); void RecordStats(HeapStats* stats);
......
...@@ -225,17 +225,15 @@ Handle<Object> LookupSingleCharacterStringFromCode(Isolate* isolate, ...@@ -225,17 +225,15 @@ Handle<Object> LookupSingleCharacterStringFromCode(Isolate* isolate,
// collector will call the weak callback on the global handle // collector will call the weak callback on the global handle
// associated with the wrapper and get rid of both the wrapper and the // associated with the wrapper and get rid of both the wrapper and the
// handle. // handle.
static void ClearWrapperCache(v8::Isolate* v8_isolate, static void ClearWrapperCache(
Persistent<v8::Value>* handle, const v8::WeakCallbackData<v8::Value, void>& data) {
void*) { Object** location = reinterpret_cast<Object**>(data.GetParameter());
Handle<Object> cache = Utils::OpenPersistent(handle); JSValue* wrapper = JSValue::cast(*location);
JSValue* wrapper = JSValue::cast(*cache);
Foreign* foreign = Script::cast(wrapper->value())->wrapper(); Foreign* foreign = Script::cast(wrapper->value())->wrapper();
ASSERT(foreign->foreign_address() == ASSERT_EQ(foreign->foreign_address(), reinterpret_cast<Address>(location));
reinterpret_cast<Address>(cache.location()));
foreign->set_foreign_address(0); foreign->set_foreign_address(0);
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate); GlobalHandles::Destroy(location);
isolate->global_handles()->Destroy(cache.location()); Isolate* isolate = reinterpret_cast<Isolate*>(data.GetIsolate());
isolate->counters()->script_wrappers()->Decrement(); isolate->counters()->script_wrappers()->Decrement();
} }
...@@ -267,9 +265,9 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script) { ...@@ -267,9 +265,9 @@ Handle<JSValue> GetScriptWrapper(Handle<Script> script) {
// for future use. The cache will automatically be cleared by the // for future use. The cache will automatically be cleared by the
// garbage collector when it is not used anymore. // garbage collector when it is not used anymore.
Handle<Object> handle = isolate->global_handles()->Create(*result); Handle<Object> handle = isolate->global_handles()->Create(*result);
isolate->global_handles()->MakeWeak(handle.location(), GlobalHandles::MakeWeak(handle.location(),
NULL, reinterpret_cast<void*>(handle.location()),
&ClearWrapperCache); &ClearWrapperCache);
script->wrapper()->set_foreign_address( script->wrapper()->set_foreign_address(
reinterpret_cast<Address>(handle.location())); reinterpret_cast<Address>(handle.location()));
return result; return result;
......
...@@ -864,15 +864,24 @@ icu::SimpleDateFormat* DateFormat::UnpackDateFormat( ...@@ -864,15 +864,24 @@ icu::SimpleDateFormat* DateFormat::UnpackDateFormat(
} }
void DateFormat::DeleteDateFormat(v8::Isolate* isolate, template<class T>
Persistent<v8::Value>* object, void DeleteNativeObjectAt(const v8::WeakCallbackData<v8::Value, void>& data,
void* param) { int index) {
// First delete the hidden C++ object. v8::Local<v8::Object> obj = v8::Handle<v8::Object>::Cast(data.GetValue());
delete reinterpret_cast<icu::SimpleDateFormat*>(Handle<JSObject>::cast( delete reinterpret_cast<T*>(obj->GetAlignedPointerFromInternalField(index));
v8::Utils::OpenPersistent(object))->GetInternalField(0)); }
// Then dispose of the persistent handle to JS object.
object->Reset(); static void DestroyGlobalHandle(
const v8::WeakCallbackData<v8::Value, void>& data) {
GlobalHandles::Destroy(reinterpret_cast<Object**>(data.GetParameter()));
}
void DateFormat::DeleteDateFormat(
const v8::WeakCallbackData<v8::Value, void>& data) {
DeleteNativeObjectAt<icu::SimpleDateFormat>(data, 0);
DestroyGlobalHandle(data);
} }
...@@ -928,15 +937,10 @@ icu::DecimalFormat* NumberFormat::UnpackNumberFormat( ...@@ -928,15 +937,10 @@ icu::DecimalFormat* NumberFormat::UnpackNumberFormat(
} }
void NumberFormat::DeleteNumberFormat(v8::Isolate* isolate, void NumberFormat::DeleteNumberFormat(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data) {
void* param) { DeleteNativeObjectAt<icu::DecimalFormat>(data, 0);
// First delete the hidden C++ object. DestroyGlobalHandle(data);
delete reinterpret_cast<icu::DecimalFormat*>(Handle<JSObject>::cast(
v8::Utils::OpenPersistent(object))->GetInternalField(0));
// Then dispose of the persistent handle to JS object.
object->Reset();
} }
...@@ -989,15 +993,10 @@ icu::Collator* Collator::UnpackCollator(Isolate* isolate, ...@@ -989,15 +993,10 @@ icu::Collator* Collator::UnpackCollator(Isolate* isolate,
} }
void Collator::DeleteCollator(v8::Isolate* isolate, void Collator::DeleteCollator(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data) {
void* param) { DeleteNativeObjectAt<icu::Collator>(data, 0);
// First delete the hidden C++ object. DestroyGlobalHandle(data);
delete reinterpret_cast<icu::Collator*>(Handle<JSObject>::cast(
v8::Utils::OpenPersistent(object))->GetInternalField(0));
// Then dispose of the persistent handle to JS object.
object->Reset();
} }
...@@ -1053,18 +1052,11 @@ icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate, ...@@ -1053,18 +1052,11 @@ icu::BreakIterator* BreakIterator::UnpackBreakIterator(Isolate* isolate,
} }
void BreakIterator::DeleteBreakIterator(v8::Isolate* isolate, void BreakIterator::DeleteBreakIterator(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data) {
void* param) { DeleteNativeObjectAt<icu::BreakIterator>(data, 0);
// First delete the hidden C++ object. DeleteNativeObjectAt<icu::UnicodeString>(data, 1);
delete reinterpret_cast<icu::BreakIterator*>(Handle<JSObject>::cast( DestroyGlobalHandle(data);
v8::Utils::OpenPersistent(object))->GetInternalField(0));
delete reinterpret_cast<icu::UnicodeString*>(Handle<JSObject>::cast(
v8::Utils::OpenPersistent(object))->GetInternalField(1));
// Then dispose of the persistent handle to JS object.
object->Reset();
} }
} } // namespace v8::internal } } // namespace v8::internal
...@@ -71,9 +71,9 @@ class DateFormat { ...@@ -71,9 +71,9 @@ class DateFormat {
// Release memory we allocated for the DateFormat once the JS object that // Release memory we allocated for the DateFormat once the JS object that
// holds the pointer gets garbage collected. // holds the pointer gets garbage collected.
static void DeleteDateFormat(v8::Isolate* isolate, static void DeleteDateFormat(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data);
void* param);
private: private:
DateFormat(); DateFormat();
}; };
...@@ -95,9 +95,9 @@ class NumberFormat { ...@@ -95,9 +95,9 @@ class NumberFormat {
// Release memory we allocated for the NumberFormat once the JS object that // Release memory we allocated for the NumberFormat once the JS object that
// holds the pointer gets garbage collected. // holds the pointer gets garbage collected.
static void DeleteNumberFormat(v8::Isolate* isolate, static void DeleteNumberFormat(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data);
void* param);
private: private:
NumberFormat(); NumberFormat();
}; };
...@@ -118,9 +118,9 @@ class Collator { ...@@ -118,9 +118,9 @@ class Collator {
// Release memory we allocated for the Collator once the JS object that holds // Release memory we allocated for the Collator once the JS object that holds
// the pointer gets garbage collected. // the pointer gets garbage collected.
static void DeleteCollator(v8::Isolate* isolate, static void DeleteCollator(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data);
void* param);
private: private:
Collator(); Collator();
}; };
...@@ -141,9 +141,8 @@ class BreakIterator { ...@@ -141,9 +141,8 @@ class BreakIterator {
// Release memory we allocated for the BreakIterator once the JS object that // Release memory we allocated for the BreakIterator once the JS object that
// holds the pointer gets garbage collected. // holds the pointer gets garbage collected.
static void DeleteBreakIterator(v8::Isolate* isolate, static void DeleteBreakIterator(
Persistent<v8::Value>* object, const v8::WeakCallbackData<v8::Value, void>& data);
void* param);
private: private:
BreakIterator(); BreakIterator();
......
...@@ -9949,8 +9949,7 @@ class ArrayConcatVisitor { ...@@ -9949,8 +9949,7 @@ class ArrayConcatVisitor {
} }
inline void clear_storage() { inline void clear_storage() {
isolate_->global_handles()->Destroy( GlobalHandles::Destroy(Handle<Object>::cast(storage_).location());
Handle<Object>::cast(storage_).location());
} }
inline void set_storage(FixedArray* storage) { inline void set_storage(FixedArray* storage) {
...@@ -13806,8 +13805,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateDateTimeFormat) { ...@@ -13806,8 +13805,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateDateTimeFormat) {
// Make object handle weak so we can delete the data format once GC kicks in. // Make object handle weak so we can delete the data format once GC kicks in.
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), GlobalHandles::MakeWeak(wrapper.location(),
NULL, reinterpret_cast<void*>(wrapper.location()),
DateFormat::DeleteDateFormat); DateFormat::DeleteDateFormat);
return *local_object; return *local_object;
} }
...@@ -13910,8 +13909,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateNumberFormat) { ...@@ -13910,8 +13909,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateNumberFormat) {
NONE)); NONE));
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), GlobalHandles::MakeWeak(wrapper.location(),
NULL, reinterpret_cast<void*>(wrapper.location()),
NumberFormat::DeleteNumberFormat); NumberFormat::DeleteNumberFormat);
return *local_object; return *local_object;
} }
...@@ -14022,8 +14021,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateCollator) { ...@@ -14022,8 +14021,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateCollator) {
NONE)); NONE));
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), GlobalHandles::MakeWeak(wrapper.location(),
NULL, reinterpret_cast<void*>(wrapper.location()),
Collator::DeleteCollator); Collator::DeleteCollator);
return *local_object; return *local_object;
} }
...@@ -14098,8 +14097,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) { ...@@ -14098,8 +14097,8 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateBreakIterator) {
// Make object handle weak so we can delete the break iterator once GC kicks // Make object handle weak so we can delete the break iterator once GC kicks
// in. // in.
Handle<Object> wrapper = isolate->global_handles()->Create(*local_object); Handle<Object> wrapper = isolate->global_handles()->Create(*local_object);
GlobalHandles::MakeWeak(reinterpret_cast<Object**>(wrapper.location()), GlobalHandles::MakeWeak(wrapper.location(),
NULL, reinterpret_cast<void*>(wrapper.location()),
BreakIterator::DeleteBreakIterator); BreakIterator::DeleteBreakIterator);
return *local_object; return *local_object;
} }
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <stdlib.h> #include <stdlib.h>
#include <utility>
#include "v8.h" #include "v8.h"
...@@ -382,22 +383,24 @@ TEST(GlobalHandles) { ...@@ -382,22 +383,24 @@ TEST(GlobalHandles) {
CHECK((*h4)->IsHeapNumber()); CHECK((*h4)->IsHeapNumber());
CHECK_EQ(*h3, *h1); CHECK_EQ(*h3, *h1);
global_handles->Destroy(h1.location()); GlobalHandles::Destroy(h1.location());
global_handles->Destroy(h3.location()); GlobalHandles::Destroy(h3.location());
CHECK_EQ(*h4, *h2); CHECK_EQ(*h4, *h2);
global_handles->Destroy(h2.location()); GlobalHandles::Destroy(h2.location());
global_handles->Destroy(h4.location()); GlobalHandles::Destroy(h4.location());
} }
static bool WeakPointerCleared = false; static bool WeakPointerCleared = false;
static void TestWeakGlobalHandleCallback(v8::Isolate* isolate, static void TestWeakGlobalHandleCallback(
v8::Persistent<v8::Value>* handle, const v8::WeakCallbackData<v8::Value, void>& data) {
void* id) { std::pair<v8::Persistent<v8::Value>*, int>* p =
if (1234 == reinterpret_cast<intptr_t>(id)) WeakPointerCleared = true; reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
handle->Reset(); data.GetParameter());
if (p->second == 1234) WeakPointerCleared = true;
p->first->Reset();
} }
...@@ -424,9 +427,10 @@ TEST(WeakGlobalHandlesScavenge) { ...@@ -424,9 +427,10 @@ TEST(WeakGlobalHandlesScavenge) {
h2 = global_handles->Create(*u); h2 = global_handles->Create(*u);
} }
global_handles->MakeWeak(h2.location(), std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(h2.location(),
&TestWeakGlobalHandleCallback); reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback);
// Scavenge treats weak pointers as normal roots. // Scavenge treats weak pointers as normal roots.
heap->PerformScavenge(); heap->PerformScavenge();
...@@ -438,8 +442,8 @@ TEST(WeakGlobalHandlesScavenge) { ...@@ -438,8 +442,8 @@ TEST(WeakGlobalHandlesScavenge) {
CHECK(!global_handles->IsNearDeath(h2.location())); CHECK(!global_handles->IsNearDeath(h2.location()));
CHECK(!global_handles->IsNearDeath(h1.location())); CHECK(!global_handles->IsNearDeath(h1.location()));
global_handles->Destroy(h1.location()); GlobalHandles::Destroy(h1.location());
global_handles->Destroy(h2.location()); GlobalHandles::Destroy(h2.location());
} }
...@@ -470,9 +474,10 @@ TEST(WeakGlobalHandlesMark) { ...@@ -470,9 +474,10 @@ TEST(WeakGlobalHandlesMark) {
heap->CollectGarbage(NEW_SPACE); heap->CollectGarbage(NEW_SPACE);
CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2)); CHECK(!heap->InNewSpace(*h1) && !heap->InNewSpace(*h2));
global_handles->MakeWeak(h2.location(), std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(h2.location(),
&TestWeakGlobalHandleCallback); reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback);
CHECK(!GlobalHandles::IsNearDeath(h1.location())); CHECK(!GlobalHandles::IsNearDeath(h1.location()));
CHECK(!GlobalHandles::IsNearDeath(h2.location())); CHECK(!GlobalHandles::IsNearDeath(h2.location()));
...@@ -484,7 +489,7 @@ TEST(WeakGlobalHandlesMark) { ...@@ -484,7 +489,7 @@ TEST(WeakGlobalHandlesMark) {
CHECK(WeakPointerCleared); CHECK(WeakPointerCleared);
CHECK(!GlobalHandles::IsNearDeath(h1.location())); CHECK(!GlobalHandles::IsNearDeath(h1.location()));
global_handles->Destroy(h1.location()); GlobalHandles::Destroy(h1.location());
} }
...@@ -507,9 +512,10 @@ TEST(DeleteWeakGlobalHandle) { ...@@ -507,9 +512,10 @@ TEST(DeleteWeakGlobalHandle) {
h = global_handles->Create(*i); h = global_handles->Create(*i);
} }
global_handles->MakeWeak(h.location(), std::pair<Handle<Object>*, int> handle_and_id(&h, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(h.location(),
&TestWeakGlobalHandleCallback); reinterpret_cast<void*>(&handle_and_id),
&TestWeakGlobalHandleCallback);
// Scanvenge does not recognize weak reference. // Scanvenge does not recognize weak reference.
heap->PerformScavenge(); heap->PerformScavenge();
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <errno.h> #include <errno.h>
#endif #endif
#include <utility>
#include "v8.h" #include "v8.h"
...@@ -245,12 +246,14 @@ TEST(MapCompact) { ...@@ -245,12 +246,14 @@ TEST(MapCompact) {
static int NumberOfWeakCalls = 0; static int NumberOfWeakCalls = 0;
static void WeakPointerCallback(v8::Isolate* isolate, static void WeakPointerCallback(
v8::Persistent<v8::Value>* handle, const v8::WeakCallbackData<v8::Value, void>& data) {
void* id) { std::pair<v8::Persistent<v8::Value>*, int>* p =
ASSERT(id == reinterpret_cast<void*>(1234)); reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
data.GetParameter());
ASSERT_EQ(1234, p->second);
NumberOfWeakCalls++; NumberOfWeakCalls++;
handle->Reset(); p->first->Reset();
} }
...@@ -268,15 +271,18 @@ TEST(ObjectGroups) { ...@@ -268,15 +271,18 @@ TEST(ObjectGroups) {
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
Handle<Object> g1c1 = Handle<Object> g1c1 =
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
global_handles->MakeWeak(g1s1.location(), std::pair<Handle<Object>*, int> g1s1_and_id(&g1s1, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(g1s1.location(),
&WeakPointerCallback); reinterpret_cast<void*>(&g1s1_and_id),
global_handles->MakeWeak(g1s2.location(), &WeakPointerCallback);
reinterpret_cast<void*>(1234), std::pair<Handle<Object>*, int> g1s2_and_id(&g1s2, 1234);
&WeakPointerCallback); GlobalHandles::MakeWeak(g1s2.location(),
global_handles->MakeWeak(g1c1.location(), reinterpret_cast<void*>(&g1s2_and_id),
reinterpret_cast<void*>(1234), &WeakPointerCallback);
&WeakPointerCallback); std::pair<Handle<Object>*, int> g1c1_and_id(&g1c1, 1234);
GlobalHandles::MakeWeak(g1c1.location(),
reinterpret_cast<void*>(&g1c1_and_id),
&WeakPointerCallback);
Handle<Object> g2s1 = Handle<Object> g2s1 =
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
...@@ -284,15 +290,18 @@ TEST(ObjectGroups) { ...@@ -284,15 +290,18 @@ TEST(ObjectGroups) {
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
Handle<Object> g2c1 = Handle<Object> g2c1 =
global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked()); global_handles->Create(heap->AllocateFixedArray(1)->ToObjectChecked());
global_handles->MakeWeak(g2s1.location(), std::pair<Handle<Object>*, int> g2s1_and_id(&g2s1, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(g2s1.location(),
&WeakPointerCallback); reinterpret_cast<void*>(&g2s1_and_id),
global_handles->MakeWeak(g2s2.location(), &WeakPointerCallback);
reinterpret_cast<void*>(1234), std::pair<Handle<Object>*, int> g2s2_and_id(&g2s2, 1234);
&WeakPointerCallback); GlobalHandles::MakeWeak(g2s2.location(),
global_handles->MakeWeak(g2c1.location(), reinterpret_cast<void*>(&g2s2_and_id),
reinterpret_cast<void*>(1234), &WeakPointerCallback);
&WeakPointerCallback); std::pair<Handle<Object>*, int> g2c1_and_id(&g2c1, 1234);
GlobalHandles::MakeWeak(g2c1.location(),
reinterpret_cast<void*>(&g2c1_and_id),
&WeakPointerCallback);
Handle<Object> root = global_handles->Create(*g1s1); // make a root. Handle<Object> root = global_handles->Create(*g1s1); // make a root.
...@@ -319,9 +328,10 @@ TEST(ObjectGroups) { ...@@ -319,9 +328,10 @@ TEST(ObjectGroups) {
CHECK_EQ(0, NumberOfWeakCalls); CHECK_EQ(0, NumberOfWeakCalls);
// Weaken the root. // Weaken the root.
global_handles->MakeWeak(root.location(), std::pair<Handle<Object>*, int> root_and_id(&root, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(root.location(),
&WeakPointerCallback); reinterpret_cast<void*>(&root_and_id),
&WeakPointerCallback);
// But make children strong roots---all the objects (except for children) // But make children strong roots---all the objects (except for children)
// should be collectable now. // should be collectable now.
global_handles->ClearWeakness(g1c1.location()); global_handles->ClearWeakness(g1c1.location());
...@@ -347,12 +357,12 @@ TEST(ObjectGroups) { ...@@ -347,12 +357,12 @@ TEST(ObjectGroups) {
CHECK_EQ(5, NumberOfWeakCalls); CHECK_EQ(5, NumberOfWeakCalls);
// And now make children weak again and collect them. // And now make children weak again and collect them.
global_handles->MakeWeak(g1c1.location(), GlobalHandles::MakeWeak(g1c1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(&g1c1_and_id),
&WeakPointerCallback); &WeakPointerCallback);
global_handles->MakeWeak(g2c1.location(), GlobalHandles::MakeWeak(g2c1.location(),
reinterpret_cast<void*>(1234), reinterpret_cast<void*>(&g2c1_and_id),
&WeakPointerCallback); &WeakPointerCallback);
heap->CollectGarbage(OLD_POINTER_SPACE); heap->CollectGarbage(OLD_POINTER_SPACE);
CHECK_EQ(7, NumberOfWeakCalls); CHECK_EQ(7, NumberOfWeakCalls);
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <utility>
#include "v8.h" #include "v8.h"
#include "global-handles.h" #include "global-handles.h"
...@@ -64,12 +66,14 @@ static void PutIntoWeakMap(Handle<JSWeakMap> weakmap, ...@@ -64,12 +66,14 @@ static void PutIntoWeakMap(Handle<JSWeakMap> weakmap,
} }
static int NumberOfWeakCalls = 0; static int NumberOfWeakCalls = 0;
static void WeakPointerCallback(v8::Isolate* isolate, static void WeakPointerCallback(
v8::Persistent<v8::Value>* handle, const v8::WeakCallbackData<v8::Value, void>& data) {
void* id) { std::pair<v8::Persistent<v8::Value>*, int>* p =
ASSERT(id == reinterpret_cast<void*>(1234)); reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
data.GetParameter());
ASSERT_EQ(1234, p->second);
NumberOfWeakCalls++; NumberOfWeakCalls++;
handle->Reset(); p->first->Reset();
} }
...@@ -112,9 +116,10 @@ TEST(Weakness) { ...@@ -112,9 +116,10 @@ TEST(Weakness) {
// Make the global reference to the key weak. // Make the global reference to the key weak.
{ {
HandleScope scope(isolate); HandleScope scope(isolate);
global_handles->MakeWeak(key.location(), std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(key.location(),
&WeakPointerCallback); reinterpret_cast<void*>(&handle_and_id),
&WeakPointerCallback);
} }
CHECK(global_handles->IsWeak(key.location())); CHECK(global_handles->IsWeak(key.location()));
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include <utility>
#include "v8.h" #include "v8.h"
#include "global-handles.h" #include "global-handles.h"
...@@ -64,12 +66,14 @@ static void PutIntoWeakSet(Handle<JSWeakSet> weakset, ...@@ -64,12 +66,14 @@ static void PutIntoWeakSet(Handle<JSWeakSet> weakset,
} }
static int NumberOfWeakCalls = 0; static int NumberOfWeakCalls = 0;
static void WeakPointerCallback(v8::Isolate* isolate, static void WeakPointerCallback(
v8::Persistent<v8::Value>* handle, const v8::WeakCallbackData<v8::Value, void>& data) {
void* id) { std::pair<v8::Persistent<v8::Value>*, int>* p =
ASSERT(id == reinterpret_cast<void*>(1234)); reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
data.GetParameter());
ASSERT_EQ(1234, p->second);
NumberOfWeakCalls++; NumberOfWeakCalls++;
handle->Reset(); p->first->Reset();
} }
...@@ -112,9 +116,10 @@ TEST(WeakSet_Weakness) { ...@@ -112,9 +116,10 @@ TEST(WeakSet_Weakness) {
// Make the global reference to the key weak. // Make the global reference to the key weak.
{ {
HandleScope scope(isolate); HandleScope scope(isolate);
global_handles->MakeWeak(key.location(), std::pair<Handle<Object>*, int> handle_and_id(&key, 1234);
reinterpret_cast<void*>(1234), GlobalHandles::MakeWeak(key.location(),
&WeakPointerCallback); reinterpret_cast<void*>(&handle_and_id),
&WeakPointerCallback);
} }
CHECK(global_handles->IsWeak(key.location())); CHECK(global_handles->IsWeak(key.location()));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment