Revision: 5662
Author: [email protected]
Date: Tue Oct 19 07:22:59 2010
Log: [Isolates] Fix auto extraction of isolate from heap objects in handle
constructor.
My previous attempt used Handle(T*) and Handle(HeapObject*) overloads,
but since T is a class template parameter (and not just a paramer of
the constructor) the first signature is preferred when the argument is
convertible to T*.
This patch exposed an issue with SaveContext which created a handle
pointing to NULL context.
Bonus: a few lint fixes.
Review URL: http://codereview.chromium.org/3788008
http://code.google.com/p/v8/source/detail?r=5662
Modified:
/branches/experimental/isolates/src/bootstrapper.cc
/branches/experimental/isolates/src/debug.cc
/branches/experimental/isolates/src/debug.h
/branches/experimental/isolates/src/execution.cc
/branches/experimental/isolates/src/handles-inl.h
/branches/experimental/isolates/src/handles.h
/branches/experimental/isolates/src/heap-inl.h
/branches/experimental/isolates/src/isolate.h
/branches/experimental/isolates/src/jsregexp.cc
/branches/experimental/isolates/src/runtime.cc
/branches/experimental/isolates/src/string-search.cc
=======================================
--- /branches/experimental/isolates/src/bootstrapper.cc Thu Oct 14 20:21:08
2010
+++ /branches/experimental/isolates/src/bootstrapper.cc Tue Oct 19 07:22:59
2010
@@ -1398,20 +1398,21 @@
global_context()->set_jsfunction_result_caches(*caches);
}
+
void Genesis::InitializeNormalizedMapCaches() {
Handle<FixedArray> array(
FACTORY->NewFixedArray(NormalizedMapCache::kEntries, TENURED));
global_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array));
}
-
bool Bootstrapper::InstallExtensions(Handle<Context> global_context,
v8::ExtensionConfiguration*
extensions) {
+ Isolate* isolate = Isolate::Current();
BootstrapperActive active;
- SaveContext saved_context;
- Isolate::Current()->set_context(*global_context);
+ SaveContext saved_context(isolate);
+ isolate->set_context(*global_context);
if (!Genesis::InstallExtensions(global_context, extensions)) return
false;
Genesis::InstallSpecialObjects(global_context);
return true;
@@ -1749,7 +1750,7 @@
// Before creating the roots we must save the context and restore it
// on all function exits.
HandleScope scope;
- SaveContext saved_context;
+ SaveContext saved_context(isolate);
Handle<Context> new_context = Snapshot::NewContextFromSnapshot();
if (!new_context.is_null()) {
=======================================
--- /branches/experimental/isolates/src/debug.cc Thu Oct 14 20:21:08 2010
+++ /branches/experimental/isolates/src/debug.cc Tue Oct 19 07:22:59 2010
@@ -104,9 +104,7 @@
Handle<Context> context =
isolate->debug()->debugger_entry()->GetContext();
// Isolate::context() may have been NULL when "script collected" event
// occured.
- if (*context == NULL) {
- return v8::Local<v8::Context>();
- }
+ if (context.is_null()) return v8::Local<v8::Context>();
Handle<Context> global_context(context->global_context());
return v8::Utils::ToLocal(global_context);
}
@@ -851,7 +849,7 @@
NULL);
// Use the debugger context.
- SaveContext save;
+ SaveContext save(isolate);
isolate->set_context(*context);
// Expose the builtins object in the debugger context.
=======================================
--- /branches/experimental/isolates/src/debug.h Fri Sep 24 17:27:22 2010
+++ /branches/experimental/isolates/src/debug.h Tue Oct 19 07:22:59 2010
@@ -850,7 +850,8 @@
EnterDebugger()
: isolate_(Isolate::Current()),
prev_(isolate_->debug()->debugger_entry()),
- has_js_frames_(!it_.done()) {
+ has_js_frames_(!it_.done()),
+ save_(isolate_) {
Debug* debug = isolate_->debug();
ASSERT(prev_ != NULL || !debug->is_interrupt_pending(PREEMPT));
ASSERT(prev_ != NULL || !debug->is_interrupt_pending(DEBUGBREAK));
=======================================
--- /branches/experimental/isolates/src/execution.cc Thu Oct 14 20:21:08
2010
+++ /branches/experimental/isolates/src/execution.cc Tue Oct 19 07:22:59
2010
@@ -69,6 +69,8 @@
int argc,
Object*** args,
bool* has_pending_exception) {
+ Isolate* isolate = func->GetIsolate();
+
// Entering JavaScript.
VMState state(JS);
@@ -106,7 +108,7 @@
{
// Save and restore context around invocation and block the
// allocation of handles without explicit handle scopes.
- SaveContext save;
+ SaveContext save(isolate);
NoHandleAllocation na;
JSEntryFunction entry = FUNCTION_CAST<JSEntryFunction>(code->entry());
@@ -126,13 +128,13 @@
*has_pending_exception = value->IsException();
ASSERT(*has_pending_exception ==
Isolate::Current()->has_pending_exception());
if (*has_pending_exception) {
- Isolate::Current()->ReportPendingMessages();
+ isolate->ReportPendingMessages();
return Handle<Object>();
} else {
- Isolate::Current()->clear_pending_message();
+ isolate->clear_pending_message();
}
- return Handle<Object>(value);
+ return Handle<Object>(value, isolate);
}
=======================================
--- /branches/experimental/isolates/src/handles-inl.h Fri Oct 1 11:01:30
2010
+++ /branches/experimental/isolates/src/handles-inl.h Tue Oct 19 07:22:59
2010
@@ -37,15 +37,18 @@
namespace v8 {
namespace internal {
-template<class T>
-Handle<T>::Handle(T* obj) {
- ASSERT(!obj->IsFailure());
- location_ = HandleScope::CreateHandle(obj, Isolate::Current());
+inline Isolate* GetIsolateForHandle(Object* obj) {
+ return Isolate::Current();
+}
+
+inline Isolate* GetIsolateForHandle(HeapObject* obj) {
+ return obj->GetIsolate();
}
template<class T>
-Handle<T>::Handle(HeapObject* obj) {
- location_ = HandleScope::CreateHandle<T>(obj, obj->GetIsolate());
+Handle<T>::Handle(T* obj) {
+ ASSERT(!obj->IsFailure());
+ location_ = HandleScope::CreateHandle(obj, GetIsolateForHandle(obj));
}
=======================================
--- /branches/experimental/isolates/src/handles.h Thu Oct 14 20:21:08 2010
+++ /branches/experimental/isolates/src/handles.h Tue Oct 19 07:22:59 2010
@@ -44,7 +44,6 @@
public:
INLINE(explicit Handle(T** location)) { location_ = location; }
INLINE(explicit Handle(T* obj));
- INLINE(explicit Handle(HeapObject* obj));
INLINE(Handle(T* obj, Isolate* isolate));
INLINE(Handle()) : location_(NULL) {}
=======================================
--- /branches/experimental/isolates/src/heap-inl.h Thu Oct 14 20:21:08 2010
+++ /branches/experimental/isolates/src/heap-inl.h Tue Oct 19 07:22:59 2010
@@ -427,8 +427,9 @@
v8::internal::V8::FatalProcessOutOfMemory("CALL_AND_RETRY_0", true);\
} \
if (!__object__->IsRetryAfterGC()) RETURN_EMPTY; \
-
ISOLATE->heap()->CollectGarbage(Failure::cast(__object__)->requested(),\
- Failure::cast(__object__)->allocation_space()); \
+ ISOLATE->heap()->CollectGarbage( \
+ Failure::cast(__object__)->requested(), \
+ Failure::cast(__object__)->allocation_space()); \
__object__ = FUNCTION_CALL; \
if (!__object__->IsFailure()) RETURN_VALUE; \
if (__object__->IsOutOfMemoryFailure()) { \
=======================================
--- /branches/experimental/isolates/src/isolate.h Thu Oct 14 20:21:08 2010
+++ /branches/experimental/isolates/src/isolate.h Tue Oct 19 07:22:59 2010
@@ -638,8 +638,8 @@
static const char* const kStackOverflowMessage;
- static const int kUC16AlphabetSize = 256; // See StringSearchBase.
- static const int kBMMaxShift = 250; // See StringSearchBase.
+ static const int kUC16AlphabetSize = 256; // See StringSearchBase.
+ static const int kBMMaxShift = 250; // See StringSearchBase.
// Accessors.
#define GLOBAL_ACCESSOR(type, name,
initialvalue) \
@@ -1045,13 +1045,14 @@
// versions of GCC. See V8 issue 122 for details.
class SaveContext BASE_EMBEDDED {
public:
- SaveContext()
- : context_(Isolate::Current()->context()),
+ explicit SaveContext(Isolate* isolate) : prev_(isolate->save_context()) {
+ if (isolate->context() != NULL) {
+ context_ = Handle<Context>(isolate->context());
#if __GNUC_VERSION__ >= 40100 && __GNUC_VERSION__ < 40300
- dummy_(Isolate::Current()->context()),
+ dummy_ = Handle<Context>(isolate->context());
#endif
- prev_(Isolate::Current()->save_context()) {
- Isolate::Current()->set_save_context(this);
+ }
+ isolate->set_save_context(this);
// If there is no JS frame under the current C frame, use the value 0.
JavaScriptFrameIterator it;
@@ -1059,8 +1060,15 @@
}
~SaveContext() {
- Isolate::Current()->set_context(*context_);
- Isolate::Current()->set_save_context(prev_);
+ if (context_.is_null()) {
+ Isolate* isolate = Isolate::Current();
+ isolate->set_context(NULL);
+ isolate->set_save_context(prev_);
+ } else {
+ Isolate* isolate = context_->GetIsolate();
+ isolate->set_context(*context_);
+ isolate->set_save_context(prev_);
+ }
}
Handle<Context> context() { return context_; }
=======================================
--- /branches/experimental/isolates/src/jsregexp.cc Thu Oct 14 20:21:08 2010
+++ /branches/experimental/isolates/src/jsregexp.cc Tue Oct 19 07:22:59 2010
@@ -98,7 +98,8 @@
Handle<JSArray> array = isolate->factory()->NewJSArray(2);
SetElement(array, 0, pattern);
SetElement(array, 1, error_text);
- Handle<Object> regexp_err = isolate->factory()->NewSyntaxError(message,
array);
+ Handle<Object> regexp_err = isolate->factory()->NewSyntaxError(message,
+ array);
isolate->Throw(*regexp_err);
}
=======================================
--- /branches/experimental/isolates/src/runtime.cc Thu Oct 14 20:21:08 2010
+++ /branches/experimental/isolates/src/runtime.cc Tue Oct 19 07:22:59 2010
@@ -8140,7 +8140,7 @@
// into the embedding application can occour, and the embedding
application
// could have the assumption that its own global context is the current
// context and not some internal debugger context.
- SaveContext save;
+ SaveContext save(isolate);
if (isolate->debug()->InDebugger()) {
isolate->set_context(*isolate->debug()->debugger_entry()->GetContext());
}
@@ -9527,7 +9527,7 @@
save = save->prev();
}
ASSERT(save != NULL);
- SaveContext savex;
+ SaveContext savex(isolate);
isolate->set_context(*(save->context()));
// Create the (empty) function replacing the function on the stack frame
for
@@ -9626,7 +9626,7 @@
DisableBreak disable_break_save(disable_break);
// Enter the top context from before the debugger was invoked.
- SaveContext save;
+ SaveContext save(isolate);
SaveContext* top = &save;
while (top != NULL && *top->context() ==
*isolate->debug()->debug_context()) {
top = top->prev();
=======================================
--- /branches/experimental/isolates/src/string-search.cc Thu Oct 14
20:21:08 2010
+++ /branches/experimental/isolates/src/string-search.cc Tue Oct 19
07:22:59 2010
@@ -38,8 +38,4 @@
// good_suffix_shift_table()
// suffix_table()
-//int StringSearchBase::kBadCharShiftTable[kUC16AlphabetSize];
-//int StringSearchBase::kGoodSuffixShiftTable[kBMMaxShift + 1];
-//int StringSearchBase::kSuffixTable[kBMMaxShift + 1];
-
}} // namespace v8::internal
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev