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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1643 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0f9253b5
// 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 @@ void** v8::HandleScope::RawClose(void** value) {
// 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 @@ static void InitializeTemplate(i::Handle<i::TemplateInfo> that, int type) {
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 @@ static int next_serial_number = 0;
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() {
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 @@ ScriptData* ScriptData::New(unsigned* data, int length) {
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 @@ void v8::Object::SetInternalField(int index, v8::Handle<Value> value) {
// --- 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 @@ Persistent<Context> v8::Context::New(
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::Empty() {
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();
......
// 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 @@ class GlobalHandles::Node : public Malloced {
// 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);
}
}
}
......
// 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 @@ Handle<JSObject> Copy(Handle<JSObject> obj) {
// 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();
......
// 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 @@ void Heap::Shrink() {
#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
......
// 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 @@ FILE* Logger::logfile_ = NULL;
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 @@ static const char* StateToString(StateTag state) {
}
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;
......
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