Skip to content

Commit 9dc621f

Browse files
committed
Upgrade v8 to 1.3.4
1 parent dd5ae31 commit 9dc621f

File tree

21 files changed

+325
-109
lines changed

21 files changed

+325
-109
lines changed

deps/v8/ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2009-08-13: Version 1.3.4
2+
3+
Added a readline() command to the d8 shell.
4+
5+
Fixed bug in json parsing.
6+
7+
Added idle notification to the API and reduced memory on idle
8+
notifications.
9+
10+
111
2009-08-12: Version 1.3.3
212

313
Fix issue 417: incorrect %t placeholder expansion.

deps/v8/include/v8.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,6 +2201,14 @@ class V8EXPORT V8 {
22012201
*/
22022202
static bool Dispose();
22032203

2204+
2205+
/**
2206+
* Optional notification that the embedder is idle.
2207+
* V8 uses the notification to reduce memory footprint.
2208+
* \param is_high_priority tells whether the embedder is high priority.
2209+
*/
2210+
static void IdleNotification(bool is_high_priority);
2211+
22042212
private:
22052213
V8();
22062214

deps/v8/src/api.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,6 +2558,10 @@ bool v8::V8::Dispose() {
25582558
}
25592559

25602560

2561+
void v8::V8::IdleNotification(bool is_high_priority) {
2562+
i::V8::IdleNotification(is_high_priority);
2563+
}
2564+
25612565
const char* v8::V8::GetVersion() {
25622566
static v8::internal::EmbeddedVector<char, 128> buffer;
25632567
v8::internal::Version::GetString(buffer);
@@ -2589,12 +2593,8 @@ Persistent<Context> v8::Context::New(
25892593
i::Handle<i::Context> env;
25902594
{
25912595
ENTER_V8;
2592-
#if defined(ANDROID)
2593-
// On mobile devices, full GC is expensive.
2594-
#else
25952596
// Give the heap a chance to cleanup if we've disposed contexts.
25962597
i::Heap::CollectAllGarbageIfContextDisposed();
2597-
#endif
25982598
v8::Handle<ObjectTemplate> proxy_template = global_template;
25992599
i::Handle<i::FunctionTemplateInfo> proxy_constructor;
26002600
i::Handle<i::FunctionTemplateInfo> global_constructor;

deps/v8/src/compiler.cc

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static Handle<Code> MakeCode(FunctionLiteral* literal,
102102

103103

104104
static bool IsValidJSON(FunctionLiteral* lit) {
105-
if (!lit->body()->length() == 1)
105+
if (lit->body()->length() != 1)
106106
return false;
107107
Statement* stmt = lit->body()->at(0);
108108
if (stmt->AsExpressionStatement() == NULL)
@@ -114,7 +114,7 @@ static bool IsValidJSON(FunctionLiteral* lit) {
114114

115115
static Handle<JSFunction> MakeFunction(bool is_global,
116116
bool is_eval,
117-
bool is_json,
117+
Compiler::ValidationState validate,
118118
Handle<Script> script,
119119
Handle<Context> context,
120120
v8::Extension* extension,
@@ -129,6 +129,7 @@ static Handle<JSFunction> MakeFunction(bool is_global,
129129
script->set_context_data((*i::Top::global_context())->data());
130130

131131
#ifdef ENABLE_DEBUGGER_SUPPORT
132+
bool is_json = (validate == Compiler::VALIDATE_JSON);
132133
if (is_eval || is_json) {
133134
script->set_compilation_type(
134135
is_json ? Smi::FromInt(Script::COMPILATION_TYPE_JSON) :
@@ -162,7 +163,7 @@ static Handle<JSFunction> MakeFunction(bool is_global,
162163
// When parsing JSON we do an ordinary parse and then afterwards
163164
// check the AST to ensure it was well-formed. If not we give a
164165
// syntax error.
165-
if (is_json && !IsValidJSON(lit)) {
166+
if (validate == Compiler::VALIDATE_JSON && !IsValidJSON(lit)) {
166167
HandleScope scope;
167168
Handle<JSArray> args = Factory::NewJSArray(1);
168169
Handle<Object> source(script->source());
@@ -282,7 +283,7 @@ Handle<JSFunction> Compiler::Compile(Handle<String> source,
282283
// Compile the function and add it to the cache.
283284
result = MakeFunction(true,
284285
false,
285-
false,
286+
DONT_VALIDATE_JSON,
286287
script,
287288
Handle<Context>::null(),
288289
extension,
@@ -305,7 +306,11 @@ Handle<JSFunction> Compiler::Compile(Handle<String> source,
305306
Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
306307
Handle<Context> context,
307308
bool is_global,
308-
bool is_json) {
309+
ValidationState validate) {
310+
// Note that if validation is required then no path through this
311+
// function is allowed to return a value without validating that
312+
// the input is legal json.
313+
309314
int source_length = source->length();
310315
Counters::total_eval_size.Increment(source_length);
311316
Counters::total_compile_size.Increment(source_length);
@@ -314,20 +319,26 @@ Handle<JSFunction> Compiler::CompileEval(Handle<String> source,
314319
VMState state(COMPILER);
315320

316321
// Do a lookup in the compilation cache; if the entry is not there,
317-
// invoke the compiler and add the result to the cache.
318-
Handle<JSFunction> result =
319-
CompilationCache::LookupEval(source, context, is_global);
322+
// invoke the compiler and add the result to the cache. If we're
323+
// evaluating json we bypass the cache since we can't be sure a
324+
// potential value in the cache has been validated.
325+
Handle<JSFunction> result;
326+
if (validate == DONT_VALIDATE_JSON)
327+
result = CompilationCache::LookupEval(source, context, is_global);
328+
320329
if (result.is_null()) {
321330
// Create a script object describing the script to be compiled.
322331
Handle<Script> script = Factory::NewScript(source);
323332
result = MakeFunction(is_global,
324333
true,
325-
is_json,
334+
validate,
326335
script,
327336
context,
328337
NULL,
329338
NULL);
330-
if (!result.is_null()) {
339+
if (!result.is_null() && validate != VALIDATE_JSON) {
340+
// For json it's unlikely that we'll ever see exactly the same
341+
// string again so we don't use the compilation cache.
331342
CompilationCache::PutEval(source, context, is_global, result);
332343
}
333344
}

deps/v8/src/compiler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ namespace internal {
4848

4949
class Compiler : public AllStatic {
5050
public:
51+
enum ValidationState { VALIDATE_JSON, DONT_VALIDATE_JSON };
52+
5153
// All routines return a JSFunction.
5254
// If an error occurs an exception is raised and
5355
// the return handle contains NULL.
@@ -63,7 +65,7 @@ class Compiler : public AllStatic {
6365
static Handle<JSFunction> CompileEval(Handle<String> source,
6466
Handle<Context> context,
6567
bool is_global,
66-
bool is_json);
68+
ValidationState validation);
6769

6870
// Compile from function info (used for lazy compilation). Returns
6971
// true on success and false if the compilation resulted in a stack

deps/v8/src/d8.cc

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ Handle<Value> Shell::Write(const Arguments& args) {
167167

168168

169169
Handle<Value> Shell::Read(const Arguments& args) {
170-
if (args.Length() != 1) {
171-
return ThrowException(String::New("Bad parameters"));
172-
}
173170
String::Utf8Value file(args[0]);
174171
if (*file == NULL) {
175172
return ThrowException(String::New("Error loading file"));
@@ -182,6 +179,19 @@ Handle<Value> Shell::Read(const Arguments& args) {
182179
}
183180

184181

182+
Handle<Value> Shell::ReadLine(const Arguments& args) {
183+
char line_buf[256];
184+
if (fgets(line_buf, sizeof(line_buf), stdin) == NULL) {
185+
return ThrowException(String::New("Error reading line"));
186+
}
187+
int len = strlen(line_buf);
188+
if (line_buf[len - 1] == '\n') {
189+
--len;
190+
}
191+
return String::New(line_buf, len);
192+
}
193+
194+
185195
Handle<Value> Shell::Load(const Arguments& args) {
186196
for (int i = 0; i < args.Length(); i++) {
187197
HandleScope handle_scope;
@@ -404,6 +414,8 @@ void Shell::Initialize() {
404414
global_template->Set(String::New("print"), FunctionTemplate::New(Print));
405415
global_template->Set(String::New("write"), FunctionTemplate::New(Write));
406416
global_template->Set(String::New("read"), FunctionTemplate::New(Read));
417+
global_template->Set(String::New("readline"),
418+
FunctionTemplate::New(ReadLine));
407419
global_template->Set(String::New("load"), FunctionTemplate::New(Load));
408420
global_template->Set(String::New("quit"), FunctionTemplate::New(Quit));
409421
global_template->Set(String::New("version"), FunctionTemplate::New(Version));
@@ -596,6 +608,8 @@ void ShellThread::Run() {
596608
FunctionTemplate::New(Shell::Write));
597609
global_template->Set(String::New("read"),
598610
FunctionTemplate::New(Shell::Read));
611+
global_template->Set(String::New("readline"),
612+
FunctionTemplate::New(Shell::ReadLine));
599613
global_template->Set(String::New("load"),
600614
FunctionTemplate::New(Shell::Load));
601615
global_template->Set(String::New("yield"),

deps/v8/src/d8.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ class Shell: public i::AllStatic {
143143
static Handle<Value> Quit(const Arguments& args);
144144
static Handle<Value> Version(const Arguments& args);
145145
static Handle<Value> Read(const Arguments& args);
146+
static Handle<Value> ReadLine(const Arguments& args);
146147
static Handle<Value> Load(const Arguments& args);
147148
// The OS object on the global object contains methods for performing
148149
// operating system calls:

deps/v8/src/flag-definitions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ DEFINE_bool(trace_gc_verbose, false,
161161
DEFINE_bool(collect_maps, true,
162162
"garbage collect maps from which no objects can be reached")
163163

164+
// v8.cc
165+
DEFINE_bool(use_idle_notification, true,
166+
"Use idle notification to reduce memory footprint.")
164167
// ic.cc
165168
DEFINE_bool(use_ic, true, "use inline caching")
166169

deps/v8/src/heap.cc

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,20 @@ static void VerifySymbolTable() {
425425
}
426426

427427

428+
void Heap::EnsureFromSpaceIsCommitted() {
429+
if (new_space_.CommitFromSpaceIfNeeded()) return;
430+
431+
// Committing memory to from space failed.
432+
// Try shrinking and try again.
433+
Shrink();
434+
if (new_space_.CommitFromSpaceIfNeeded()) return;
435+
436+
// Committing memory to from space failed again.
437+
// Memory is exhausted and we will die.
438+
V8::FatalProcessOutOfMemory("Committing semi space failed.");
439+
}
440+
441+
428442
void Heap::PerformGarbageCollection(AllocationSpace space,
429443
GarbageCollector collector,
430444
GCTracer* tracer) {
@@ -433,7 +447,7 @@ void Heap::PerformGarbageCollection(AllocationSpace space,
433447
ASSERT(!allocation_allowed_);
434448
global_gc_prologue_callback_();
435449
}
436-
450+
EnsureFromSpaceIsCommitted();
437451
if (collector == MARK_COMPACTOR) {
438452
MarkCompact(tracer);
439453

deps/v8/src/heap.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ class Heap : public AllStatic {
280280
return new_space_.allocation_limit_address();
281281
}
282282

283+
// Uncommit unused semi space.
284+
static bool UncommitFromSpace() { return new_space_.UncommitFromSpace(); }
285+
283286
#ifdef ENABLE_HEAP_PROTECTION
284287
// Protect/unprotect the heap by marking all spaces read-only/writable.
285288
static void Protect();
@@ -794,6 +797,9 @@ class Heap : public AllStatic {
794797
// Rebuild remembered set in old and map spaces.
795798
static void RebuildRSets();
796799

800+
// Commits from space if it is uncommitted.
801+
static void EnsureFromSpaceIsCommitted();
802+
797803
//
798804
// Support for the API.
799805
//

0 commit comments

Comments
 (0)