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" |
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1488 I->heap()->CollectAllGarbage(); | 1488 I->heap()->CollectAllGarbage(); |
1489 I->StopBackgroundCompiler(); | 1489 I->StopBackgroundCompiler(); |
1490 | 1490 |
1491 #if defined(DEBUG) | 1491 #if defined(DEBUG) |
1492 FunctionVisitor check_canonical(T); | 1492 FunctionVisitor check_canonical(T); |
1493 I->heap()->IterateObjects(&check_canonical); | 1493 I->heap()->IterateObjects(&check_canonical); |
1494 #endif // #if defined(DEBUG). | 1494 #endif // #if defined(DEBUG). |
1495 | 1495 |
1496 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, | 1496 FullSnapshotWriter writer(vm_isolate_snapshot_buffer, |
1497 isolate_snapshot_buffer, | 1497 isolate_snapshot_buffer, |
1498 NULL, /* instructions_snapshot_buffer */ | |
1499 ApiReallocate, | 1498 ApiReallocate, |
| 1499 NULL, /* instructions_writer */ |
1500 false, /* snapshot_code */ | 1500 false, /* snapshot_code */ |
1501 true /* vm_isolate_is_symbolic */); | 1501 true /* vm_isolate_is_symbolic */); |
1502 writer.WriteFullSnapshot(); | 1502 writer.WriteFullSnapshot(); |
1503 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1503 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
1504 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1504 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
1505 return Api::Success(); | 1505 return Api::Success(); |
1506 } | 1506 } |
1507 | 1507 |
1508 | 1508 |
1509 static Dart_Handle createLibrarySnapshot(Dart_Handle library, | 1509 static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
(...skipping 4518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6028 #if !defined(DART_PRECOMPILER) | 6028 #if !defined(DART_PRECOMPILER) |
6029 | 6029 |
6030 DART_EXPORT Dart_Handle Dart_Precompile( | 6030 DART_EXPORT Dart_Handle Dart_Precompile( |
6031 Dart_QualifiedFunctionName entry_points[], | 6031 Dart_QualifiedFunctionName entry_points[], |
6032 bool reset_fields) { | 6032 bool reset_fields) { |
6033 UNREACHABLE(); | 6033 UNREACHABLE(); |
6034 return 0; | 6034 return 0; |
6035 } | 6035 } |
6036 | 6036 |
6037 | 6037 |
6038 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( | 6038 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotAssembly( |
6039 uint8_t** vm_isolate_snapshot_buffer, | 6039 uint8_t** vm_isolate_snapshot_buffer, |
6040 intptr_t* vm_isolate_snapshot_size, | 6040 intptr_t* vm_isolate_snapshot_size, |
6041 uint8_t** isolate_snapshot_buffer, | 6041 uint8_t** isolate_snapshot_buffer, |
6042 intptr_t* isolate_snapshot_size, | 6042 intptr_t* isolate_snapshot_size, |
6043 uint8_t** instructions_snapshot_buffer, | 6043 uint8_t** assembly_buffer, |
6044 intptr_t* instructions_snapshot_size) { | 6044 intptr_t* assembly_size) { |
6045 UNREACHABLE(); | 6045 UNREACHABLE(); |
6046 return 0; | 6046 return 0; |
6047 } | 6047 } |
| 6048 |
| 6049 |
| 6050 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( |
| 6051 uint8_t** vm_isolate_snapshot_buffer, |
| 6052 intptr_t* vm_isolate_snapshot_size, |
| 6053 uint8_t** isolate_snapshot_buffer, |
| 6054 intptr_t* isolate_snapshot_size, |
| 6055 uint8_t** instructions_blob_buffer, |
| 6056 intptr_t* instructions_blob_size, |
| 6057 uint8_t** rodata_blob_buffer, |
| 6058 intptr_t* rodata_blob_size) { |
| 6059 UNREACHABLE(); |
| 6060 return 0; |
| 6061 } |
6048 | 6062 |
6049 #else // DART_PRECOMPILER | 6063 #else // DART_PRECOMPILER |
6050 | 6064 |
6051 DART_EXPORT Dart_Handle Dart_Precompile( | 6065 DART_EXPORT Dart_Handle Dart_Precompile( |
6052 Dart_QualifiedFunctionName entry_points[], | 6066 Dart_QualifiedFunctionName entry_points[], |
6053 bool reset_fields) { | 6067 bool reset_fields) { |
6054 API_TIMELINE_BEGIN_END; | 6068 API_TIMELINE_BEGIN_END; |
6055 DARTSCOPE(Thread::Current()); | 6069 DARTSCOPE(Thread::Current()); |
6056 if (!FLAG_precompiled_mode) { | 6070 if (!FLAG_precompiled_mode) { |
6057 return Dart_NewApiError("Flag --precompilation was not specified."); | 6071 return Dart_NewApiError("Flag --precompilation was not specified."); |
6058 } | 6072 } |
6059 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); | 6073 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
6060 if (::Dart_IsError(result)) { | 6074 if (::Dart_IsError(result)) { |
6061 return result; | 6075 return result; |
6062 } | 6076 } |
6063 CHECK_CALLBACK_STATE(T); | 6077 CHECK_CALLBACK_STATE(T); |
6064 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, | 6078 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, |
6065 reset_fields)); | 6079 reset_fields)); |
6066 if (!error.IsNull()) { | 6080 if (!error.IsNull()) { |
6067 return Api::NewHandle(T, error.raw()); | 6081 return Api::NewHandle(T, error.raw()); |
6068 } | 6082 } |
6069 return Api::Success(); | 6083 return Api::Success(); |
6070 } | 6084 } |
6071 | 6085 |
6072 | 6086 |
6073 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshot( | 6087 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotAssembly( |
6074 uint8_t** vm_isolate_snapshot_buffer, | 6088 uint8_t** vm_isolate_snapshot_buffer, |
6075 intptr_t* vm_isolate_snapshot_size, | 6089 intptr_t* vm_isolate_snapshot_size, |
6076 uint8_t** isolate_snapshot_buffer, | 6090 uint8_t** isolate_snapshot_buffer, |
6077 intptr_t* isolate_snapshot_size, | 6091 intptr_t* isolate_snapshot_size, |
6078 uint8_t** instructions_snapshot_buffer, | 6092 uint8_t** assembly_buffer, |
6079 intptr_t* instructions_snapshot_size) { | 6093 intptr_t* assembly_size) { |
6080 ASSERT(FLAG_load_deferred_eagerly); | 6094 ASSERT(FLAG_load_deferred_eagerly); |
6081 API_TIMELINE_DURATION; | 6095 API_TIMELINE_DURATION; |
6082 DARTSCOPE(Thread::Current()); | 6096 DARTSCOPE(Thread::Current()); |
6083 Isolate* I = T->isolate(); | 6097 Isolate* I = T->isolate(); |
6084 if (I->compilation_allowed()) { | 6098 if (I->compilation_allowed()) { |
6085 return Dart_NewApiError("Isolate is not precompiled. " | 6099 return Dart_NewApiError("Isolate is not precompiled. " |
6086 "Did you forget to call Dart_Precompile?"); | 6100 "Did you forget to call Dart_Precompile?"); |
6087 } | 6101 } |
6088 if (vm_isolate_snapshot_buffer == NULL) { | 6102 if (vm_isolate_snapshot_buffer == NULL) { |
6089 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6103 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
6090 } | 6104 } |
6091 if (vm_isolate_snapshot_size == NULL) { | 6105 if (vm_isolate_snapshot_size == NULL) { |
6092 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6106 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
6093 } | 6107 } |
6094 if (isolate_snapshot_buffer == NULL) { | 6108 if (isolate_snapshot_buffer == NULL) { |
6095 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6109 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
6096 } | 6110 } |
6097 if (isolate_snapshot_size == NULL) { | 6111 if (isolate_snapshot_size == NULL) { |
6098 RETURN_NULL_ERROR(isolate_snapshot_size); | 6112 RETURN_NULL_ERROR(isolate_snapshot_size); |
6099 } | 6113 } |
6100 if (instructions_snapshot_buffer == NULL) { | 6114 if (assembly_buffer == NULL) { |
6101 RETURN_NULL_ERROR(instructions_snapshot_buffer); | 6115 RETURN_NULL_ERROR(assembly_buffer); |
6102 } | 6116 } |
6103 if (instructions_snapshot_size == NULL) { | 6117 if (assembly_size == NULL) { |
6104 RETURN_NULL_ERROR(instructions_snapshot_size); | 6118 RETURN_NULL_ERROR(assembly_size); |
6105 } | |
6106 // Finalize all classes if needed. | |
6107 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | |
6108 if (::Dart_IsError(state)) { | |
6109 return state; | |
6110 } | 6119 } |
6111 I->heap()->CollectAllGarbage(); | 6120 I->heap()->CollectAllGarbage(); |
| 6121 AssemblyInstructionsWriter instructions_writer(assembly_buffer, |
| 6122 ApiReallocate, |
| 6123 2 * MB /* initial_size */); |
6112 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, | 6124 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, |
6113 isolate_snapshot_buffer, | 6125 isolate_snapshot_buffer, |
6114 instructions_snapshot_buffer, | 6126 ApiReallocate, |
6115 ApiReallocate); | 6127 &instructions_writer); |
6116 writer.WriteFullSnapshot(); | 6128 writer.WriteFullSnapshot(); |
6117 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6129 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
6118 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6130 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
6119 *instructions_snapshot_size = writer.InstructionsSnapshotSize(); | 6131 *assembly_size = instructions_writer.AssemblySize(); |
6120 | 6132 |
6121 return Api::Success(); | 6133 return Api::Success(); |
6122 } | 6134 } |
| 6135 |
| 6136 |
| 6137 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( |
| 6138 uint8_t** vm_isolate_snapshot_buffer, |
| 6139 intptr_t* vm_isolate_snapshot_size, |
| 6140 uint8_t** isolate_snapshot_buffer, |
| 6141 intptr_t* isolate_snapshot_size, |
| 6142 uint8_t** instructions_blob_buffer, |
| 6143 intptr_t* instructions_blob_size, |
| 6144 uint8_t** rodata_blob_buffer, |
| 6145 intptr_t* rodata_blob_size) { |
| 6146 ASSERT(FLAG_load_deferred_eagerly); |
| 6147 API_TIMELINE_DURATION; |
| 6148 DARTSCOPE(Thread::Current()); |
| 6149 Isolate* I = T->isolate(); |
| 6150 if (I->compilation_allowed()) { |
| 6151 return Dart_NewApiError("Isolate is not precompiled. " |
| 6152 "Did you forget to call Dart_Precompile?"); |
| 6153 } |
| 6154 if (vm_isolate_snapshot_buffer == NULL) { |
| 6155 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
| 6156 } |
| 6157 if (vm_isolate_snapshot_size == NULL) { |
| 6158 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
| 6159 } |
| 6160 if (isolate_snapshot_buffer == NULL) { |
| 6161 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
| 6162 } |
| 6163 if (isolate_snapshot_size == NULL) { |
| 6164 RETURN_NULL_ERROR(isolate_snapshot_size); |
| 6165 } |
| 6166 if (instructions_blob_buffer == NULL) { |
| 6167 RETURN_NULL_ERROR(instructions_blob_buffer); |
| 6168 } |
| 6169 if (instructions_blob_size == NULL) { |
| 6170 RETURN_NULL_ERROR(instructions_blob_size); |
| 6171 } |
| 6172 if (rodata_blob_buffer == NULL) { |
| 6173 RETURN_NULL_ERROR(instructions_blob_buffer); |
| 6174 } |
| 6175 if (rodata_blob_size == NULL) { |
| 6176 RETURN_NULL_ERROR(instructions_blob_size); |
| 6177 } |
| 6178 I->heap()->CollectAllGarbage(); |
| 6179 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, |
| 6180 rodata_blob_buffer, |
| 6181 ApiReallocate, |
| 6182 2 * MB /* initial_size */); |
| 6183 PrecompiledSnapshotWriter writer(vm_isolate_snapshot_buffer, |
| 6184 isolate_snapshot_buffer, |
| 6185 ApiReallocate, |
| 6186 &instructions_writer); |
| 6187 writer.WriteFullSnapshot(); |
| 6188 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
| 6189 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
| 6190 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); |
| 6191 *rodata_blob_size = instructions_writer.RodataBlobSize(); |
| 6192 |
| 6193 return Api::Success(); |
| 6194 } |
6123 #endif // DART_PRECOMPILER | 6195 #endif // DART_PRECOMPILER |
6124 | 6196 |
6125 | 6197 |
6126 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { | 6198 DART_EXPORT bool Dart_IsRunningPrecompiledCode() { |
6127 return Dart::IsRunningPrecompiledCode(); | 6199 return Dart::IsRunningPrecompiledCode(); |
6128 } | 6200 } |
6129 | 6201 |
6130 } // namespace dart | 6202 } // namespace dart |
OLD | NEW |