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

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
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 context->Enter();
ulan 2012/06/19 09:42:15 Move context->Enter(), context->Exit() inside the
Erik Corry 2012/06/19 10:20:46 Done.
315 if (i::FLAG_extra_code != NULL) {
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);
ulan 2012/06/19 09:42:15 Indentation. Do we want to exit(1) here too?
Erik Corry 2012/06/19 10:20:46 Done.
336 }
337 i += read;
338 }
339 fclose(file);
340 Local<String> source = String::New(chars);
341 TryCatch try_catch;
342 Local<Script> script = Script::Compile(source);
343 if (try_catch.HasCaught()) {
344 fprintf(stderr, "Failure compiling '%s' (see above)\n", name);
345 exit(1);
346 }
347 Handle<Value> ret = script->Run();
348 if (try_catch.HasCaught()) {
349 fprintf(stderr, "Failure running '%s'\n", name);
350 Local<Message> message = try_catch.Message();
351 Local<String> message_string = message->Get();
352 Local<String> message_line = message->GetSourceLine();
353 int len = 2 + message_string->Utf8Length() + message_line->Utf8Length();
354 char* buf = new char(len);
355 message_string->WriteUtf8(buf);
356 fprintf(stderr, "%s at line %d\n", buf, message->GetLineNumber());
357 message_line->WriteUtf8(buf);
358 fprintf(stderr, "%s\n", buf);
359 int from = message->GetStartColumn();
360 int to = message->GetEndColumn();
361 int i;
362 for (i = 0; i < from; i++) fprintf(stderr, " ");
363 for ( ; i <= to; i++) fprintf(stderr, "^");
364 fprintf(stderr, "\n");
365 exit(1);
366 }
367 }
368 context->Exit();
311 // Make sure all builtin scripts are cached. 369 // Make sure all builtin scripts are cached.
312 { HandleScope scope; 370 { HandleScope scope;
313 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) { 371 for (int i = 0; i < i::Natives::GetBuiltinsCount(); i++) {
314 i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i); 372 i::Isolate::Current()->bootstrapper()->NativesSourceLookup(i);
315 } 373 }
316 } 374 }
317 // If we don't do this then we end up with a stray root pointing at the 375 // 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. 376 // context even after we have disposed of the context.
319 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags, "mksnapshot"); 377 HEAP->CollectAllGarbage(i::Heap::kNoGCFlags, "mksnapshot");
320 i::Object* raw_context = *(v8::Utils::OpenHandle(*context)); 378 i::Object* raw_context = *(v8::Utils::OpenHandle(*context));
(...skipping 22 matching lines...) Expand all
343 sink.WriteSpaceUsed( 401 sink.WriteSpaceUsed(
344 partial_ser.CurrentAllocationAddress(i::NEW_SPACE), 402 partial_ser.CurrentAllocationAddress(i::NEW_SPACE),
345 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE), 403 partial_ser.CurrentAllocationAddress(i::OLD_POINTER_SPACE),
346 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE), 404 partial_ser.CurrentAllocationAddress(i::OLD_DATA_SPACE),
347 partial_ser.CurrentAllocationAddress(i::CODE_SPACE), 405 partial_ser.CurrentAllocationAddress(i::CODE_SPACE),
348 partial_ser.CurrentAllocationAddress(i::MAP_SPACE), 406 partial_ser.CurrentAllocationAddress(i::MAP_SPACE),
349 partial_ser.CurrentAllocationAddress(i::CELL_SPACE), 407 partial_ser.CurrentAllocationAddress(i::CELL_SPACE),
350 partial_ser.CurrentAllocationAddress(i::LO_SPACE)); 408 partial_ser.CurrentAllocationAddress(i::LO_SPACE));
351 return 0; 409 return 0;
352 } 410 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698