We can only set resource constraints before the isolate is initialized.
Since in the future, we want to initialize isolates at construction
time, we need to set constraints there.
It's possible to later modify the stack limit, so introduce an
Isolate::SetStackLimit method for that.
The SetResourceConstraints method will be deprecated. Users should pass
ResourceConstraints to Isolate::New, and use Isolate::SetStackLimit to
later modify the stack limit.
BUG=none
R=svenpanne@chromium.org
LOG=y
Review URL: https://codereview.chromium.org/
559993005
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23964
ce2b1a6d-e550-0410-aec6-
3dcde31c8c00
/**
* Sets the given ResourceConstraints on the given Isolate.
+ *
+ * Deprecated, will be removed. Pass constraints via Isolate::New or modify
+ * the stack limit via Isolate::SetStackLimit.
*/
bool V8_EXPORT SetResourceConstraints(Isolate* isolate,
ResourceConstraints* constraints);
* notified each time code is added, moved or removed.
*/
JitCodeEventHandler code_event_handler;
+
+ /**
+ * ResourceConstraints to use for the new Isolate.
+ */
+ ResourceConstraints constraints;
};
void SetJitCodeEventHandler(JitCodeEventOptions options,
JitCodeEventHandler event_handler);
+ /**
+ * Modifies the stack limit for this Isolate.
+ *
+ * \param stack_limit An address beyond which the Vm's stack may not grow.
+ *
+ * \note If you are using threads then you should hold the V8::Locker lock
+ * while setting the stack limit and you must set a non-default stack
+ * limit separately for each thread.
+ */
+ void SetStackLimit(uintptr_t stack_limit);
+
private:
template<class K, class V, class Traits> friend class PersistentValueMap;
Isolate* Isolate::New(const Isolate::CreateParams& params) {
i::Isolate* isolate = new i::Isolate();
+ Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
if (params.entry_hook) {
isolate->set_function_entry_hook(params.entry_hook);
}
isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault,
params.code_event_handler);
}
- return reinterpret_cast<Isolate*>(isolate);
+ SetResourceConstraints(v8_isolate,
+ const_cast<ResourceConstraints*>(¶ms.constraints));
+ return v8_isolate;
}
}
+void v8::Isolate::SetStackLimit(uintptr_t stack_limit) {
+ i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
+ CHECK(stack_limit);
+ isolate->stack_guard()->SetStackLimit(stack_limit);
+}
+
+
String::Utf8Value::Utf8Value(v8::Handle<v8::Value> obj)
: str_(NULL), length_(0) {
i::Isolate* isolate = i::Isolate::Current();
#ifdef ENABLE_VTUNE_JIT_INTERFACE
vTune::InitializeVtuneForV8(create_params);
#endif
- Isolate* isolate = Isolate::New(create_params);
#ifndef V8_SHARED
- v8::ResourceConstraints constraints;
- constraints.ConfigureDefaults(base::SysInfo::AmountOfPhysicalMemory(),
- base::SysInfo::AmountOfVirtualMemory(),
- base::SysInfo::NumberOfProcessors());
- v8::SetResourceConstraints(isolate, &constraints);
+ create_params.constraints.ConfigureDefaults(
+ base::SysInfo::AmountOfPhysicalMemory(),
+ base::SysInfo::AmountOfVirtualMemory(),
+ base::SysInfo::NumberOfProcessors());
#endif
+ Isolate* isolate = Isolate::New(create_params);
DumbLineEditor dumb_line_editor(isolate);
{
Isolate::Scope scope(isolate);
static const int stack_breathing_room = 256 * i::KB;
-TEST(SetResourceConstraints) {
+TEST(SetStackLimit) {
uint32_t* set_limit = ComputeStackLimit(stack_breathing_room);
// Set stack limit.
- v8::ResourceConstraints constraints;
- constraints.set_stack_limit(set_limit);
- CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints));
+ CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit));
// Execute a script.
LocalContext env;
}
-TEST(SetResourceConstraintsInThread) {
+TEST(SetStackLimitInThread) {
uint32_t* set_limit;
{
v8::Locker locker(CcTest::isolate());
set_limit = ComputeStackLimit(stack_breathing_room);
// Set stack limit.
- v8::ResourceConstraints constraints;
- constraints.set_stack_limit(set_limit);
- CHECK(v8::SetResourceConstraints(CcTest::isolate(), &constraints));
+ CcTest::isolate()->SetStackLimit(reinterpret_cast<uintptr_t>(set_limit));
// Execute a script.
v8::HandleScope scope(CcTest::isolate());
result_(false) {}
void Run() {
- v8::Isolate* isolate = v8::Isolate::New();
- isolate->Enter();
+ v8::Isolate::CreateParams create_params;
switch (testCase_) {
case SetResourceConstraints: {
- v8::ResourceConstraints constraints;
- constraints.set_max_semi_space_size(1);
- constraints.set_max_old_space_size(4);
- v8::SetResourceConstraints(CcTest::isolate(), &constraints);
+ create_params.constraints.set_max_semi_space_size(1);
+ create_params.constraints.set_max_old_space_size(4);
break;
}
+ default:
+ break;
+ }
+ v8::Isolate* isolate = v8::Isolate::New(create_params);
+ isolate->Enter();
+ switch (testCase_) {
+ case SetResourceConstraints:
+ // Already handled in pre-Isolate-creation block.
+ break;
case SetFatalHandler:
v8::V8::SetFatalErrorHandler(NULL);
}
-TEST(OneByteArrayJoin) {
+UNINITIALIZED_TEST(OneByteArrayJoin) {
+ v8::Isolate::CreateParams create_params;
// Set heap limits.
- v8::ResourceConstraints constraints;
- constraints.set_max_semi_space_size(1);
- constraints.set_max_old_space_size(4);
- v8::SetResourceConstraints(CcTest::isolate(), &constraints);
-
- // String s is made of 2^17 = 131072 'c' characters and a is an array
- // starting with 'bad', followed by 2^14 times the string s. That means the
- // total length of the concatenated strings is 2^31 + 3. So on 32bit systems
- // summing the lengths of the strings (as Smis) overflows and wraps.
- LocalContext context;
- v8::HandleScope scope(CcTest::isolate());
- v8::TryCatch try_catch;
- CHECK(CompileRun(
- "var two_14 = Math.pow(2, 14);"
- "var two_17 = Math.pow(2, 17);"
- "var s = Array(two_17 + 1).join('c');"
- "var a = ['bad'];"
- "for (var i = 1; i <= two_14; i++) a.push(s);"
- "a.join("");").IsEmpty());
- CHECK(try_catch.HasCaught());
+ create_params.constraints.set_max_semi_space_size(1);
+ create_params.constraints.set_max_old_space_size(4);
+ v8::Isolate* isolate = v8::Isolate::New(create_params);
+ isolate->Enter();
+
+ {
+ // String s is made of 2^17 = 131072 'c' characters and a is an array
+ // starting with 'bad', followed by 2^14 times the string s. That means the
+ // total length of the concatenated strings is 2^31 + 3. So on 32bit systems
+ // summing the lengths of the strings (as Smis) overflows and wraps.
+ LocalContext context(isolate);
+ v8::HandleScope scope(isolate);
+ v8::TryCatch try_catch;
+ CHECK(CompileRun(
+ "var two_14 = Math.pow(2, 14);"
+ "var two_17 = Math.pow(2, 17);"
+ "var s = Array(two_17 + 1).join('c');"
+ "var a = ['bad'];"
+ "for (var i = 1; i <= two_14; i++) a.push(s);"
+ "a.join("
+ ");").IsEmpty());
+ CHECK(try_catch.HasCaught());
+ }
+ isolate->Exit();
+ isolate->Dispose();
}