This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Upgrade v8 to 1.3.4

  • Loading branch information...
1 parent dd5ae31 commit 9dc621f83a6ea79e95b7b9780df164df0b28bac7 @ry ry committed Aug 13, 2009
View
@@ -1,3 +1,13 @@
+2009-08-13: Version 1.3.4
+
+ Added a readline() command to the d8 shell.
+
+ Fixed bug in json parsing.
+
+ Added idle notification to the API and reduced memory on idle
+ notifications.
+
+
2009-08-12: Version 1.3.3
Fix issue 417: incorrect %t placeholder expansion.
View
@@ -2201,6 +2201,14 @@ class V8EXPORT V8 {
*/
static bool Dispose();
+
+ /**
+ * Optional notification that the embedder is idle.
+ * V8 uses the notification to reduce memory footprint.
+ * \param is_high_priority tells whether the embedder is high priority.
+ */
+ static void IdleNotification(bool is_high_priority);
+
private:
V8();
View
@@ -2558,6 +2558,10 @@ bool v8::V8::Dispose() {
}
+void v8::V8::IdleNotification(bool is_high_priority) {
+ i::V8::IdleNotification(is_high_priority);
+}
+
const char* v8::V8::GetVersion() {
static v8::internal::EmbeddedVector<char, 128> buffer;
v8::internal::Version::GetString(buffer);
@@ -2589,12 +2593,8 @@ Persistent<Context> v8::Context::New(
i::Handle<i::Context> env;
{
ENTER_V8;
-#if defined(ANDROID)
- // On mobile devices, full GC is expensive.
-#else
// Give the heap a chance to cleanup if we've disposed contexts.
i::Heap::CollectAllGarbageIfContextDisposed();
-#endif
v8::Handle<ObjectTemplate> proxy_template = global_template;
i::Handle<i::FunctionTemplateInfo> proxy_constructor;
i::Handle<i::FunctionTemplateInfo> global_constructor;
View
@@ -102,7 +102,7 @@ static Handle<Code> MakeCode(FunctionLiteral* literal,
static bool IsValidJSON(FunctionLiteral* lit) {
- if (!lit->body()->length() == 1)
+ if (lit->body()->length() != 1)
return false;
Statement* stmt = lit->body()->at(0);
if (stmt->AsExpressionStatement() == NULL)
@@ -114,7 +114,7 @@ static bool IsValidJSON(FunctionLiteral* lit) {
static Handle<JSFunction> MakeFunction(bool is_global,
bool is_eval,
- bool is_json,
+ Compiler::ValidationState validate,
Handle<Script> script,
Handle<Context> context,
v8::Extension* extension,
@@ -129,6 +129,7 @@ static Handle<JSFunction> MakeFunction(bool is_global,
script->set_context_data((*i::Top::global_context())->data());
#ifdef ENABLE_DEBUGGER_SUPPORT
+ bool is_json = (validate == Compiler::VALIDATE_JSON);
if (is_eval || is_json) {
script->set_compilation_type(
is_json ? Smi::FromInt(Script::COMPILATION_TYPE_JSON) :
@@ -162,7 +163,7 @@ static Handle<JSFunction> MakeFunction(bool is_global,
// When parsing JSON we do an ordinary parse and then afterwards
// check the AST to ensure it was well-formed. If not we give a
// syntax error.
- if (is_json && !IsValidJSON(lit)) {
+ if (validate == Compiler::VALIDATE_JSON && !IsValidJSON(lit)) {
HandleScope scope;
Handle<JSArray> args = Factory::NewJSArray(1);
Handle<Object> source(script->source());
@@ -282,7 +283,7 @@ Handle<JSFunction> Compiler::Compile(Handle<String> source,
// Compile the function and add it to the cache.
result = MakeFunction(true,
false,
- false,
+ DONT_VALIDATE_JSON,
script,
Handle<Context>::null(),
extension,
@@ -305,7 +306,11 @@ Handle<JSFunction> Compiler::Compile(Handle<String> source,
Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
Handle<Context> context,
bool is_global,
- bool is_json) {
+ ValidationState validate) {
+ // Note that if validation is required then no path through this
+ // function is allowed to return a value without validating that
+ // the input is legal json.
+
int source_length = source->length();
Counters::total_eval_size.Increment(source_length);
Counters::total_compile_size.Increment(source_length);
@@ -314,20 +319,26 @@ Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
VMState state(COMPILER);
// Do a lookup in the compilation cache; if the entry is not there,
- // invoke the compiler and add the result to the cache.
- Handle<JSFunction> result =
- CompilationCache::LookupEval(source, context, is_global);
+ // invoke the compiler and add the result to the cache. If we're
+ // evaluating json we bypass the cache since we can't be sure a
+ // potential value in the cache has been validated.
+ Handle<JSFunction> result;
+ if (validate == DONT_VALIDATE_JSON)
+ result = CompilationCache::LookupEval(source, context, is_global);
+
if (result.is_null()) {
// Create a script object describing the script to be compiled.
Handle<Script> script = Factory::NewScript(source);
result = MakeFunction(is_global,
true,
- is_json,
+ validate,
script,
context,
NULL,
NULL);
- if (!result.is_null()) {
+ if (!result.is_null() && validate != VALIDATE_JSON) {
+ // For json it's unlikely that we'll ever see exactly the same
+ // string again so we don't use the compilation cache.
CompilationCache::PutEval(source, context, is_global, result);
}
}
View
@@ -48,6 +48,8 @@ namespace internal {
class Compiler : public AllStatic {
public:
+ enum ValidationState { VALIDATE_JSON, DONT_VALIDATE_JSON };
+
// All routines return a JSFunction.
// If an error occurs an exception is raised and
// the return handle contains NULL.
@@ -63,7 +65,7 @@ class Compiler : public AllStatic {
static Handle<JSFunction> CompileEval(Handle<String> source,
Handle<Context> context,
bool is_global,
- bool is_json);
+ ValidationState validation);
// Compile from function info (used for lazy compilation). Returns
// true on success and false if the compilation resulted in a stack
View
@@ -167,9 +167,6 @@ Handle<Value> Shell::Write(const Arguments& args) {
Handle<Value> Shell::Read(const Arguments& args) {
- if (args.Length() != 1) {
- return ThrowException(String::New("Bad parameters"));
- }
String::Utf8Value file(args[0]);
if (*file == NULL) {
return ThrowException(String::New("Error loading file"));
@@ -182,6 +179,19 @@ Handle<Value> Shell::Read(const Arguments& args) {
}
+Handle<Value> Shell::ReadLine(const Arguments& args) {
+ char line_buf[256];
+ if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) {
+ return ThrowException(String::New("Error reading line"));
+ }
+ int len = strlen(line_buf);
+ if (line_buf[len - 1] == '\n') {
+ --len;
+ }
+ return String::New(line_buf, len);
+}
+
+
Handle<Value> Shell::Load(const Arguments& args) {
for (int i = 0; i < args.Length(); i++) {
HandleScope handle_scope;
@@ -404,6 +414,8 @@ void Shell::Initialize() {
global_template->Set(String::New("print"), FunctionTemplate::New(Print));
global_template->Set(String::New("write"), FunctionTemplate::New(Write));
global_template->Set(String::New("read"), FunctionTemplate::New(Read));
+ global_template->Set(String::New("readline"),
+ FunctionTemplate::New(ReadLine));
global_template->Set(String::New("load"), FunctionTemplate::New(Load));
global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
global_template->Set(String::New("version"), FunctionTemplate::New(Version));
@@ -596,6 +608,8 @@ void ShellThread::Run() {
FunctionTemplate::New(Shell::Write));
global_template->Set(String::New("read"),
FunctionTemplate::New(Shell::Read));
+ global_template->Set(String::New("readline"),
+ FunctionTemplate::New(Shell::ReadLine));
global_template->Set(String::New("load"),
FunctionTemplate::New(Shell::Load));
global_template->Set(String::New("yield"),
View
@@ -143,6 +143,7 @@ class Shell: public i::AllStatic {
static Handle<Value> Quit(const Arguments& args);
static Handle<Value> Version(const Arguments& args);
static Handle<Value> Read(const Arguments& args);
+ static Handle<Value> ReadLine(const Arguments& args);
static Handle<Value> Load(const Arguments& args);
// The OS object on the global object contains methods for performing
// operating system calls:
@@ -161,6 +161,9 @@ DEFINE_bool(trace_gc_verbose, false,
DEFINE_bool(collect_maps, true,
"garbage collect maps from which no objects can be reached")
+// v8.cc
+DEFINE_bool(use_idle_notification, true,
+ "Use idle notification to reduce memory footprint.")
// ic.cc
DEFINE_bool(use_ic, true, "use inline caching")
View
@@ -425,6 +425,20 @@ static void VerifySymbolTable() {
}
+void Heap::EnsureFromSpaceIsCommitted() {
+ if (new_space_.CommitFromSpaceIfNeeded()) return;
+
+ // Committing memory to from space failed.
+ // Try shrinking and try again.
+ Shrink();
+ if (new_space_.CommitFromSpaceIfNeeded()) return;
+
+ // Committing memory to from space failed again.
+ // Memory is exhausted and we will die.
+ V8::FatalProcessOutOfMemory("Committing semi space failed.");
+}
+
+
void Heap::PerformGarbageCollection(AllocationSpace space,
GarbageCollector collector,
GCTracer* tracer) {
@@ -433,7 +447,7 @@ void Heap::PerformGarbageCollection(AllocationSpace space,
ASSERT(!allocation_allowed_);
global_gc_prologue_callback_();
}
-
+ EnsureFromSpaceIsCommitted();
if (collector == MARK_COMPACTOR) {
MarkCompact(tracer);
View
@@ -280,6 +280,9 @@ class Heap : public AllStatic {
return new_space_.allocation_limit_address();
}
+ // Uncommit unused semi space.
+ static bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); }
+
#ifdef ENABLE_HEAP_PROTECTION
// Protect/unprotect the heap by marking all spaces read-only/writable.
static void Protect();
@@ -794,6 +797,9 @@ class Heap : public AllStatic {
// Rebuild remembered set in old and map spaces.
static void RebuildRSets();
+ // Commits from space if it is uncommitted.
+ static void EnsureFromSpaceIsCommitted();
+
//
// Support for the API.
//
Oops, something went wrong.

0 comments on commit 9dc621f

Please sign in to comment.