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