OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
11 #include "vm/class_finalizer.h" | 11 #include "vm/class_finalizer.h" |
12 #include "vm/clustered_snapshot.h" | 12 #include "vm/clustered_snapshot.h" |
13 #include "vm/compiler.h" | 13 #include "vm/compiler.h" |
14 #include "vm/dart.h" | 14 #include "vm/dart.h" |
15 #include "vm/dart_api_impl.h" | 15 #include "vm/dart_api_impl.h" |
16 #include "vm/dart_api_message.h" | 16 #include "vm/dart_api_message.h" |
17 #include "vm/dart_api_state.h" | 17 #include "vm/dart_api_state.h" |
18 #include "vm/dart_entry.h" | 18 #include "vm/dart_entry.h" |
19 #include "vm/debugger.h" | 19 #include "vm/debugger.h" |
| 20 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 21 #include "vm/kernel_reader.h" |
| 22 #endif |
20 #include "vm/exceptions.h" | 23 #include "vm/exceptions.h" |
21 #include "vm/flags.h" | 24 #include "vm/flags.h" |
22 #include "vm/growable_array.h" | 25 #include "vm/growable_array.h" |
23 #include "vm/lockers.h" | 26 #include "vm/lockers.h" |
24 #include "vm/isolate_reload.h" | 27 #include "vm/isolate_reload.h" |
25 #include "vm/message.h" | 28 #include "vm/message.h" |
26 #include "vm/message_handler.h" | 29 #include "vm/message_handler.h" |
27 #include "vm/native_entry.h" | 30 #include "vm/native_entry.h" |
28 #include "vm/object.h" | 31 #include "vm/object.h" |
29 #include "vm/object_store.h" | 32 #include "vm/object_store.h" |
(...skipping 5355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5385 tds2.FormatArgument(1, "heapSize", "%" Pd64, | 5388 tds2.FormatArgument(1, "heapSize", "%" Pd64, |
5386 I->heap()->UsedInWords(Heap::kOld) * kWordSize); | 5389 I->heap()->UsedInWords(Heap::kOld) * kWordSize); |
5387 }); | 5390 }); |
5388 library ^= tmp.raw(); | 5391 library ^= tmp.raw(); |
5389 library.set_debuggable(true); | 5392 library.set_debuggable(true); |
5390 I->object_store()->set_root_library(library); | 5393 I->object_store()->set_root_library(library); |
5391 return Api::NewHandle(T, library.raw()); | 5394 return Api::NewHandle(T, library.raw()); |
5392 } | 5395 } |
5393 | 5396 |
5394 | 5397 |
| 5398 DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer, |
| 5399 intptr_t buffer_len) { |
| 5400 API_TIMELINE_DURATION; |
| 5401 DARTSCOPE(Thread::Current()); |
| 5402 StackZone zone(T); |
| 5403 |
| 5404 #if defined(DART_PRECOMPILED_RUNTIME) && !defined(DART_PRECOMPILER) |
| 5405 return Api::NewError("%s: Can't load Kernel files from precompiled runtime.", |
| 5406 CURRENT_FUNC); |
| 5407 #else |
| 5408 Isolate* I = T->isolate(); |
| 5409 |
| 5410 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
| 5411 if (!library.IsNull()) { |
| 5412 const String& library_url = String::Handle(Z, library.url()); |
| 5413 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 5414 CURRENT_FUNC, library_url.ToCString()); |
| 5415 } |
| 5416 CHECK_CALLBACK_STATE(T); |
| 5417 CHECK_COMPILATION_ALLOWED(I); |
| 5418 |
| 5419 // TODO(27588): Memory leak! |
| 5420 kernel::KernelReader* reader = new kernel::KernelReader(buffer, buffer_len); |
| 5421 const Object& tmp = reader->ReadProgram(); |
| 5422 if (tmp.IsError()) { |
| 5423 return Api::NewHandle(T, tmp.raw()); |
| 5424 } |
| 5425 library ^= tmp.raw(); |
| 5426 library.set_debuggable(false); |
| 5427 I->object_store()->set_root_library(library); |
| 5428 return Api::NewHandle(T, library.raw()); |
| 5429 #endif |
| 5430 } |
| 5431 |
| 5432 |
5395 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 5433 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
5396 Thread* thread = Thread::Current(); | 5434 Thread* thread = Thread::Current(); |
5397 Isolate* isolate = thread->isolate(); | 5435 Isolate* isolate = thread->isolate(); |
5398 CHECK_ISOLATE(isolate); | 5436 CHECK_ISOLATE(isolate); |
5399 return Api::NewHandle(thread, isolate->object_store()->root_library()); | 5437 return Api::NewHandle(thread, isolate->object_store()->root_library()); |
5400 } | 5438 } |
5401 | 5439 |
5402 | 5440 |
5403 DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library) { | 5441 DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library) { |
5404 DARTSCOPE(Thread::Current()); | 5442 DARTSCOPE(Thread::Current()); |
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6621 | 6659 |
6622 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6660 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
6623 #if defined(DART_PRECOMPILED_RUNTIME) | 6661 #if defined(DART_PRECOMPILED_RUNTIME) |
6624 return true; | 6662 return true; |
6625 #else | 6663 #else |
6626 return false; | 6664 return false; |
6627 #endif | 6665 #endif |
6628 } | 6666 } |
6629 | 6667 |
6630 } // namespace dart | 6668 } // namespace dart |
OLD | NEW |