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
This commit is contained in:
kmillikin@chromium.org 2009-03-30 13:32:28 +00:00
parent 0f9253b537
commit d3ee29a7f6
5 changed files with 54 additions and 19 deletions

View File

@ -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 @@ 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();

View File

@ -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 @@ 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);
}
}
}

View File

@ -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 @@ 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();

View File

@ -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,6 +2864,7 @@ void Heap::Shrink() {
#ifdef ENABLE_HEAP_PROTECTION
void Heap::Protect() {
if (HasBeenSetup()) {
new_space_.Protect();
map_space_->Protect();
old_pointer_space_->Protect();
@ -2871,9 +2872,11 @@ void Heap::Protect() {
code_space_->Protect();
lo_space_->Protect();
}
}
void Heap::Unprotect() {
if (HasBeenSetup()) {
new_space_.Unprotect();
map_space_->Unprotect();
old_pointer_space_->Unprotect();
@ -2881,6 +2884,7 @@ void Heap::Unprotect() {
code_space_->Unprotect();
lo_space_->Unprotect();
}
}
#endif

View File

@ -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 @@ 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;