Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(381)

Side by Side Diff: src/mksnapshot.cc

Issue 10574013: Snapshots: Add --extra-code flag to mksnapshot which lets you specify a file (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/isolate.cc ('k') | src/serialize.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #include <errno.h>
29 #include <stdio.h>
28 #ifdef COMPRESS_STARTUP_DATA_BZ2 30 #ifdef COMPRESS_STARTUP_DATA_BZ2
29 #include <bzlib.h> 31 #include <bzlib.h>
30 #endif 32 #endif
31 #include <signal.h> 33 #include <signal.h>
32 34
33 #include "v8.h" 35 #include "v8.h"
34 36
35 #include "bootstrapper.h" 37 #include "bootstrapper.h"
38 #include "flags.h"
36 #include "natives.h" 39 #include "natives.h"
37 #include "platform.h" 40 #include "platform.h"
38 #include "serialize.h" 41 #include "serialize.h"
39 #include "list.h" 42 #include "list.h"
40 43
41 using namespace v8; 44 using namespace v8;
42 45
43 static const unsigned int kMaxCounters = 256; 46 static const unsigned int kMaxCounters = 256;
44 47
45 // A single counter in a counter collection. 48 // A single counter in a counter collection.
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 exit(1); 304 exit(1);
302 } 305 }
303 #endif 306 #endif
304 i::Serializer::Enable(); 307 i::Serializer::Enable();
305 Persistent<Context> context = v8::Context::New(); 308 Persistent<Context> context = v8::Context::New();
306 if (context.IsEmpty()) { 309 if (context.IsEmpty()) {
307 fprintf(stderr, 310 fprintf(stderr,
308 "\nException thrown while compiling natives - see above.\n\n"); 311 "\nException thrown while compiling natives - see above.\n\n");
309 exit(1); 312 exit(1);
310 } 313 }
314 if (i::FLAG_extra_code != NULL) {
315 context->Enter();
316 // Capture 100 frames if anything happens.
317 V8::SetCaptureStackTraceForUncaughtExceptions(true, 100);
318 HandleScope scope;
319 const char* name = i::FLAG_extra_code;
320 FILE* file = i::OS::FOpen(name, "rb");
321 if (file == NULL) {
322 fprintf(stderr, "Failed to open '%s': errno %d\n", name, errno);
323 exit(1);
324 }
325
326 fseek(file, 0, SEEK_END);
327 int size = ftell(file);
328 rewind(file);
329
330 char* chars = new char[size + 1];
331 chars[size] = '\0';
332 for (int i = 0; i < size;) {
333 int read = static_cast<int>(fread(&chars[i], 1, size - i, file));
334 if (read < 0) {
335 fprintf(stderr, "Failed to read '%s': errno %d\n", name, errno);
336 exit(1);
337 }
338 i += read;
339 }
340 fclose(file);
341 Local<String> source = String::New(chars);
342 TryCatch try_catch;
343 Local<Script> script = Script::Compile(source);
344 if (try_catch.HasCaught()) {
345 fprintf(stderr, "Failure compiling '%s' (see above)\n", name);
346 exit(1);
347 }
348 Handle<Value> ret = script->Run();
349 if (try_catch.HasCaught()) {
350 fprintf(stderr, "Failure running '%s'\n", name);
351 Local<Message> message = try_catch.Message();
352 Local<String> message_string = message->Get();
353 Local<String> message_line = message->GetSourceLine();
354 int len = 2 + message_string->Utf8Length() + message_line->Utf8Length();
355 char* buf = new char(len);
356 message_string->WriteUtf8(buf);
357 fprintf(stderr, "%s at line %d\n", buf, message->GetLineNumber());
358 message_line->WriteUtf8(buf);
359 fprintf(stderr, "%s\n", buf);
360 int from = message->GetStartColumn();
361 int to = message->GetEndColumn();
362 int i;
363 for (i = 0; i < from; i++) fprintf(stderr, " ");
364 for ( ; i <= to; i++) fprintf(stderr, "^");
365 fprintf(stderr, "\n");
366 exit(1);
367 }
368 context->Exit();
369 }
311 // Make sure all builtin scripts are cached. 370 // Make sure all builtin scripts are cached.
312 { HandleScope scope; 371 { HandleScope scope;
313 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { 372 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
314 i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i); 373 i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i);
315 } 374 }
316 } 375 }
317 // If we don't do this then we end up with a stray root pointing at the 376 // If we don't do this then we end up with a stray root pointing at the
318 // context even after we have disposed of the context. 377 // context even after we have disposed of the context.
319 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags, "mksnapshot"); 378 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags, "mksnapshot");
320 i::Object* raw_context = *(v8::Utils::OpenHandle(*context)); 379 i::Object* raw_context = *(v8::Utils::OpenHandle(*context));
(...skipping 22 matching lines...) Expand all
343 sink.WriteSpaceUsed( 402 sink.WriteSpaceUsed(
344 partial_ser.CurrentAllocationAddress(i::NEW_SPACE), 403 partial_ser.CurrentAllocationAddress(i::NEW_SPACE),
345 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), 404 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE),
346 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), 405 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE),
347 partial_ser.CurrentAllocationAddress(i::CODE_SPACE), 406 partial_ser.CurrentAllocationAddress(i::CODE_SPACE),
348 partial_ser.CurrentAllocationAddress(i::MAP_SPACE), 407 partial_ser.CurrentAllocationAddress(i::MAP_SPACE),
349 partial_ser.CurrentAllocationAddress(i::CELL_SPACE), 408 partial_ser.CurrentAllocationAddress(i::CELL_SPACE),
350 partial_ser.CurrentAllocationAddress(i::LO_SPACE)); 409 partial_ser.CurrentAllocationAddress(i::LO_SPACE));
351 return 0; 410 return 0;
352 } 411 }
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | src/serialize.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698