Author: [email protected]
Date: Mon Mar 30 06:32:28 2009
New Revision: 1643
Modified:
branches/bleeding_edge/src/api.cc
branches/bleeding_edge/src/global-handles.cc
branches/bleeding_edge/src/handles.cc
branches/bleeding_edge/src/heap.cc
branches/bleeding_edge/src/log.cc
Log:
Add just enough state changes from EXTERNAL (outside V8) to OTHER
(generic state inside V8) in the API to allow the V8 shell to run all
the mjsunit tests with heap protection on.
These state changes are only taken when built with
ENABLE_HEAP_PROTECTION. The two states OTHER and EXTERNAL are treated
the same because we will not properly reenter OTHER through the API.
Review URL: http://codereview.chromium.org/56060
Modified: branches/bleeding_edge/src/api.cc
==============================================================================
--- branches/bleeding_edge/src/api.cc (original)
+++ branches/bleeding_edge/src/api.cc Mon Mar 30 06:32:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -41,6 +41,12 @@
#define LOG_API(expr) LOG(ApiEntryCall(expr))
+#ifdef ENABLE_HEAP_PROTECTION
+#define ENTER_V8 i::VMState __state__(i::OTHER)
+#else
+#define ENTER_V8 ((void) 0)
+#endif
+
namespace v8 {
@@ -459,6 +465,7 @@
// NeanderObject constructor. When you add one to the site calling the
// constructor you should check that you ensured the VM was not dead first.
NeanderObject::NeanderObject(int size) {
+ ENTER_V8;
EnsureInitialized("v8::Nowhere");
value_ = i::Factory::NewNeanderObject();
i::Handle<i::FixedArray> elements = i::Factory::NewFixedArray(size);
@@ -523,6 +530,7 @@
void Template::Set(v8::Handle<String> name, v8::Handle<Data> value,
v8::PropertyAttribute attribute) {
+ ENTER_V8;
if (IsDeadCheck("v8::Template::SetProperty()")) return;
HandleScope scope;
i::Handle<i::Object> list(Utils::OpenHandle(this)->property_list());
@@ -571,6 +579,7 @@
Local<FunctionTemplate> FunctionTemplate::New(InvocationCallback callback,
v8::Handle<Value> data, v8::Handle<Signature> signature) {
+ ENTER_V8;
EnsureInitialized("v8::FunctionTemplate::New()");
LOG_API("FunctionTemplate::New");
i::Handle<i::Struct> struct_obj =
@@ -803,6 +812,7 @@
Local<ObjectTemplate> ObjectTemplate::New(
v8::Handle<FunctionTemplate> constructor) {
+ ENTER_V8;
if (IsDeadCheck("v8::ObjectTemplate::New()")) return
Local<ObjectTemplate>();
EnsureInitialized("v8::ObjectTemplate::New()");
LOG_API("ObjectTemplate::New");
@@ -988,6 +998,7 @@
Local<Script> Script::Compile(v8::Handle<String> source,
v8::ScriptOrigin* origin,
v8::ScriptData* script_data) {
+ ENTER_V8;
ON_BAILOUT("v8::Script::Compile()", return Local<Script>());
LOG_API("Script::Compile");
i::Handle<i::String> str = Utils::OpenHandle(*source);
@@ -2262,6 +2273,7 @@
// --- E n v i r o n m e n t ---
bool v8::V8::Initialize() {
+ ENTER_V8;
if (i::V8::HasBeenSetup()) return true;
HandleScope scope;
if (i::Snapshot::Initialize()) {
@@ -2299,6 +2311,7 @@
v8::ExtensionConfiguration* extensions,
v8::Handle<ObjectTemplate> global_template,
v8::Handle<Value> global_object) {
+ ENTER_V8;
EnsureInitialized("v8::Context::New()");
LOG_API("Context::New");
ON_BAILOUT("v8::Context::New()", return Persistent<Context>());
@@ -2525,6 +2538,7 @@
Local<String> v8::String::New(const char* data, int length) {
+ ENTER_V8;
EnsureInitialized("v8::String::New()");
LOG_API("String::New(char)");
if (length == 0) return Empty();
Modified: branches/bleeding_edge/src/global-handles.cc
==============================================================================
--- branches/bleeding_edge/src/global-handles.cc (original)
+++ branches/bleeding_edge/src/global-handles.cc Mon Mar 30 06:32:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2007-2008 the V8 project authors. All rights reserved.
+// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -153,7 +153,12 @@
// behavior.
WeakReferenceCallback func = callback();
if (func != NULL) {
- func(v8::Persistent<v8::Object>(ToApi<v8::Object>(handle())), par);
+ v8::Persistent<v8::Object> object = ToApi<v8::Object>(handle());
+ {
+ // Leaving V8.
+ VMState state(EXTERNAL);
+ func(object, par);
+ }
}
}
Modified: branches/bleeding_edge/src/handles.cc
==============================================================================
--- branches/bleeding_edge/src/handles.cc (original)
+++ branches/bleeding_edge/src/handles.cc Mon Mar 30 06:32:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -308,6 +308,11 @@
// associated with the wrapper and get rid of both the wrapper and the
// handle.
static void ClearWrapperCache(Persistent<v8::Value> handle, void*) {
+#ifdef ENABLE_HEAP_PROTECTION
+ // Weak reference callbacks are called as if from outside V8. We
+ // need to reeenter to unprotect the heap.
+ VMState state(OTHER);
+#endif
Handle<Object> cache = Utils::OpenHandle(*handle);
JSValue* wrapper = JSValue::cast(*cache);
Proxy* proxy = Script::cast(wrapper->value())->wrapper();
Modified: branches/bleeding_edge/src/heap.cc
==============================================================================
--- branches/bleeding_edge/src/heap.cc (original)
+++ branches/bleeding_edge/src/heap.cc Mon Mar 30 06:32:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -2864,22 +2864,26 @@
#ifdef ENABLE_HEAP_PROTECTION
void Heap::Protect() {
- new_space_.Protect();
- map_space_->Protect();
- old_pointer_space_->Protect();
- old_data_space_->Protect();
- code_space_->Protect();
- lo_space_->Protect();
+ if (HasBeenSetup()) {
+ new_space_.Protect();
+ map_space_->Protect();
+ old_pointer_space_->Protect();
+ old_data_space_->Protect();
+ code_space_->Protect();
+ lo_space_->Protect();
+ }
}
void Heap::Unprotect() {
- new_space_.Unprotect();
- map_space_->Unprotect();
- old_pointer_space_->Unprotect();
- old_data_space_->Unprotect();
- code_space_->Unprotect();
- lo_space_->Unprotect();
+ if (HasBeenSetup()) {
+ new_space_.Unprotect();
+ map_space_->Unprotect();
+ old_pointer_space_->Unprotect();
+ old_data_space_->Unprotect();
+ code_space_->Unprotect();
+ lo_space_->Unprotect();
+ }
}
#endif
Modified: branches/bleeding_edge/src/log.cc
==============================================================================
--- branches/bleeding_edge/src/log.cc (original)
+++ branches/bleeding_edge/src/log.cc Mon Mar 30 06:32:28 2009
@@ -1,4 +1,4 @@
-// Copyright 2006-2008 the V8 project authors. All rights reserved.
+// Copyright 2009 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
@@ -407,7 +407,7 @@
Profiler* Logger::profiler_ = NULL;
Mutex* Logger::mutex_ = NULL;
VMState* Logger::current_state_ = NULL;
-VMState Logger::bottom_state_(OTHER);
+VMState Logger::bottom_state_(EXTERNAL);
SlidingStateWindow* Logger::sliding_state_window_ = NULL;
#endif // ENABLE_LOGGING_AND_PROFILING
@@ -1110,6 +1110,13 @@
}
VMState::VMState(StateTag state) {
+#if !defined(ENABLE_HEAP_PROTECTION)
+ // When not protecting the heap, there is no difference between
+ // EXTERNAL and OTHER. As an optimizatin in that case, we will not
+ // perform EXTERNAL->OTHER transitions through the API. We thus
+ // compress the two states into one.
+ if (state == EXTERNAL) state = OTHER;
+#endif
state_ = state;
previous_ = Logger::current_state_;
Logger::current_state_ = this;
--~--~---------~--~----~------------~-------~--~----~
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
-~----------~----~----~----~------~----~------~--~---