OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 2 * Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
3 * for details. All rights reserved. Use of this source code is governed by a | 3 * for details. All rights reserved. Use of this source code is governed by a |
4 * BSD-style license that can be found in the LICENSE file. | 4 * BSD-style license that can be found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
7 #ifndef RUNTIME_INCLUDE_DART_API_H_ | 7 #ifndef RUNTIME_INCLUDE_DART_API_H_ |
8 #define RUNTIME_INCLUDE_DART_API_H_ | 8 #define RUNTIME_INCLUDE_DART_API_H_ |
9 | 9 |
10 /** \mainpage Dart Embedding API Reference | 10 /** \mainpage Dart Embedding API Reference |
(...skipping 755 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
766 * | 766 * |
767 * \return The embedder must return a handle to a Uint8List containing an | 767 * \return The embedder must return a handle to a Uint8List containing an |
768 * uncompressed tar archive or null. | 768 * uncompressed tar archive or null. |
769 */ | 769 */ |
770 typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(); | 770 typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(); |
771 | 771 |
772 /** | 772 /** |
773 * The current version of the Dart_InitializeFlags. Should be incremented every | 773 * The current version of the Dart_InitializeFlags. Should be incremented every |
774 * time Dart_InitializeFlags changes in a binary incompatible way. | 774 * time Dart_InitializeFlags changes in a binary incompatible way. |
775 */ | 775 */ |
776 #define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000001) | 776 #define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000002) |
777 | 777 |
778 /** | 778 /** |
779 * Describes how to initialize the VM. Used with Dart_Initialize. | 779 * Describes how to initialize the VM. Used with Dart_Initialize. |
780 * | 780 * |
781 * \param version Identifies the version of the struct used by the client. | 781 * \param version Identifies the version of the struct used by the client. |
782 * should be initialized to DART_INITIALIZE_PARAMS_CURRENT_VERSION. | 782 * should be initialized to DART_INITIALIZE_PARAMS_CURRENT_VERSION. |
783 * \param vm_isolate_snapshot A buffer containing a snapshot of the VM isolate | 783 * \param vm_isolate_snapshot A buffer containing a snapshot of the VM isolate |
784 * or NULL if no snapshot is provided. | 784 * or NULL if no snapshot is provided. |
785 * \param instructions_snapshot A buffer containing a snapshot of precompiled | 785 * \param instructions_snapshot A buffer containing a snapshot of precompiled |
786 * instructions, or NULL if no snapshot is provided. | 786 * instructions, or NULL if no snapshot is provided. |
787 * \param create A function to be called during isolate creation. | 787 * \param create A function to be called during isolate creation. |
788 * See Dart_IsolateCreateCallback. | 788 * See Dart_IsolateCreateCallback. |
789 * \param shutdown A function to be called when an isolate is shutdown. | 789 * \param shutdown A function to be called when an isolate is shutdown. |
790 * See Dart_IsolateShutdownCallback. | 790 * See Dart_IsolateShutdownCallback. |
791 * \param get_service_assets A function to be called by the service isolate when | 791 * \param get_service_assets A function to be called by the service isolate when |
792 * it requires the vmservice assets archive. | 792 * it requires the vmservice assets archive. |
793 * See Dart_GetVMServiceAssetsArchive. | 793 * See Dart_GetVMServiceAssetsArchive. |
794 */ | 794 */ |
795 typedef struct { | 795 typedef struct { |
796 int32_t version; | 796 int32_t version; |
797 const uint8_t* vm_isolate_snapshot; | 797 const uint8_t* vm_snapshot_data; |
798 const uint8_t* instructions_snapshot; | 798 const uint8_t* vm_snapshot_instructions; |
799 const uint8_t* data_snapshot; | |
800 Dart_IsolateCreateCallback create; | 799 Dart_IsolateCreateCallback create; |
801 Dart_IsolateShutdownCallback shutdown; | 800 Dart_IsolateShutdownCallback shutdown; |
802 Dart_ThreadExitCallback thread_exit; | 801 Dart_ThreadExitCallback thread_exit; |
803 Dart_FileOpenCallback file_open; | 802 Dart_FileOpenCallback file_open; |
804 Dart_FileReadCallback file_read; | 803 Dart_FileReadCallback file_read; |
805 Dart_FileWriteCallback file_write; | 804 Dart_FileWriteCallback file_write; |
806 Dart_FileCloseCallback file_close; | 805 Dart_FileCloseCallback file_close; |
807 Dart_EntropySource entropy_source; | 806 Dart_EntropySource entropy_source; |
808 Dart_GetVMServiceAssetsArchive get_service_assets; | 807 Dart_GetVMServiceAssetsArchive get_service_assets; |
809 } Dart_InitializeParams; | 808 } Dart_InitializeParams; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
857 * isolate will be started using that snapshot data. Requires a core snapshot or | 856 * isolate will be started using that snapshot data. Requires a core snapshot or |
858 * an app snapshot created by Dart_CreateSnapshot or | 857 * an app snapshot created by Dart_CreateSnapshot or |
859 * Dart_CreatePrecompiledSnapshot* from a VM with the same version. | 858 * Dart_CreatePrecompiledSnapshot* from a VM with the same version. |
860 * | 859 * |
861 * Requires there to be no current isolate. | 860 * Requires there to be no current isolate. |
862 * | 861 * |
863 * \param script_uri The name of the script this isolate will load. | 862 * \param script_uri The name of the script this isolate will load. |
864 * Provided only for advisory purposes to improve debugging messages. | 863 * Provided only for advisory purposes to improve debugging messages. |
865 * \param main The name of the main entry point this isolate will run. | 864 * \param main The name of the main entry point this isolate will run. |
866 * Provided only for advisory purposes to improve debugging messages. | 865 * Provided only for advisory purposes to improve debugging messages. |
867 * \param snapshot A buffer containing a snapshot of the isolate or | 866 * \param isolate_snapshot_data |
868 * NULL if no snapshot is provided. | 867 * \param isolate_snapshot_instructions Buffers containing a snapshot of the |
| 868 * isolate or NULL if no snapshot is provided. |
869 * \param flags Pointer to VM specific flags or NULL for default flags. | 869 * \param flags Pointer to VM specific flags or NULL for default flags. |
870 * \param callback_data Embedder data. This data will be passed to | 870 * \param callback_data Embedder data. This data will be passed to |
871 * the Dart_IsolateCreateCallback when new isolates are spawned from | 871 * the Dart_IsolateCreateCallback when new isolates are spawned from |
872 * this parent isolate. | 872 * this parent isolate. |
873 * \param error DOCUMENT | 873 * \param error DOCUMENT |
874 * | 874 * |
875 * \return The new isolate is returned. May be NULL if an error | 875 * \return The new isolate is returned. May be NULL if an error |
876 * occurs during isolate initialization. | 876 * occurs during isolate initialization. |
877 */ | 877 */ |
878 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, | 878 DART_EXPORT Dart_Isolate |
879 const char* main, | 879 Dart_CreateIsolate(const char* script_uri, |
880 const uint8_t* snapshot, | 880 const char* main, |
881 Dart_IsolateFlags* flags, | 881 const uint8_t* isolate_snapshot_data, |
882 void* callback_data, | 882 const uint8_t* isolate_snapshot_instructions, |
883 char** error); | 883 Dart_IsolateFlags* flags, |
| 884 void* callback_data, |
| 885 char** error); |
884 /* TODO(turnidge): Document behavior when there is already a current | 886 /* TODO(turnidge): Document behavior when there is already a current |
885 * isolate. */ | 887 * isolate. */ |
886 | 888 |
887 /** | 889 /** |
888 * Creates a new isolate from a Dart Kernel file. The new isolate | 890 * Creates a new isolate from a Dart Kernel file. The new isolate |
889 * becomes the current isolate. | 891 * becomes the current isolate. |
890 * | 892 * |
891 * Requires there to be no current isolate. | 893 * Requires there to be no current isolate. |
892 * | 894 * |
893 * After this call, the `kernel_program` needs to be supplied to a call to | 895 * After this call, the `kernel_program` needs to be supplied to a call to |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1002 * Requires there to be a current isolate. | 1004 * Requires there to be a current isolate. |
1003 * | 1005 * |
1004 * \param buffer Returns a pointer to a buffer containing the | 1006 * \param buffer Returns a pointer to a buffer containing the |
1005 * snapshot. This buffer is scope allocated and is only valid | 1007 * snapshot. This buffer is scope allocated and is only valid |
1006 * until the next call to Dart_ExitScope. | 1008 * until the next call to Dart_ExitScope. |
1007 * \param size Returns the size of the buffer. | 1009 * \param size Returns the size of the buffer. |
1008 * | 1010 * |
1009 * \return A valid handle if no error occurs during the operation. | 1011 * \return A valid handle if no error occurs during the operation. |
1010 */ | 1012 */ |
1011 DART_EXPORT Dart_Handle | 1013 DART_EXPORT Dart_Handle |
1012 Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer, | 1014 Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer, |
1013 intptr_t* vm_isolate_snapshot_size, | 1015 intptr_t* vm_snapshot_data_size, |
1014 uint8_t** isolate_snapshot_buffer, | 1016 uint8_t** isolate_snapshot_data_buffer, |
1015 intptr_t* isolate_snapshot_size); | 1017 intptr_t* isolate_snapshot_data_size); |
1016 | 1018 |
1017 /** | 1019 /** |
1018 * Creates a snapshot of the application script loaded in the isolate. | 1020 * Creates a snapshot of the application script loaded in the isolate. |
1019 * | 1021 * |
1020 * A script snapshot can be used for implementing fast startup of applications | 1022 * A script snapshot can be used for implementing fast startup of applications |
1021 * (skips the script tokenizing and parsing process). A Snapshot of the script | 1023 * (skips the script tokenizing and parsing process). A Snapshot of the script |
1022 * can only be created before any dart code has executed. | 1024 * can only be created before any dart code has executed. |
1023 * | 1025 * |
1024 * Requires there to be a current isolate which already has loaded script. | 1026 * Requires there to be a current isolate which already has loaded script. |
1025 * | 1027 * |
1026 * \param buffer Returns a pointer to a buffer containing | 1028 * \param buffer Returns a pointer to a buffer containing |
1027 * the snapshot. This buffer is scope allocated and is only valid | 1029 * the snapshot. This buffer is scope allocated and is only valid |
1028 * until the next call to Dart_ExitScope. | 1030 * until the next call to Dart_ExitScope. |
1029 * \param size Returns the size of the buffer. | 1031 * \param size Returns the size of the buffer. |
1030 * | 1032 * |
1031 * \return A valid handle if no error occurs during the operation. | 1033 * \return A valid handle if no error occurs during the operation. |
1032 */ | 1034 */ |
1033 DART_EXPORT Dart_Handle Dart_CreateScriptSnapshot(uint8_t** buffer, | 1035 DART_EXPORT Dart_Handle |
1034 intptr_t* size); | 1036 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer, |
| 1037 intptr_t* script_snapshot_size); |
1035 | 1038 |
1036 /** | 1039 /** |
1037 * Schedules an interrupt for the specified isolate. | 1040 * Schedules an interrupt for the specified isolate. |
1038 * | 1041 * |
1039 * When the isolate is interrupted, the isolate interrupt callback | 1042 * When the isolate is interrupted, the isolate interrupt callback |
1040 * will be invoked with 'isolate' as the current isolate (see | 1043 * will be invoked with 'isolate' as the current isolate (see |
1041 * Dart_SetIsolateEventHandler). | 1044 * Dart_SetIsolateEventHandler). |
1042 * | 1045 * |
1043 * \param isolate The isolate to be interrupted. | 1046 * \param isolate The isolate to be interrupted. |
1044 */ | 1047 */ |
(...skipping 1787 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2832 * Loads the root script for current isolate from a script snapshot. The | 2835 * Loads the root script for current isolate from a script snapshot. The |
2833 * snapshot must have been created by Dart_CreateScriptSnapshot from a VM with | 2836 * snapshot must have been created by Dart_CreateScriptSnapshot from a VM with |
2834 * the same version. | 2837 * the same version. |
2835 * | 2838 * |
2836 * \param buffer A buffer which contains a snapshot of the script. | 2839 * \param buffer A buffer which contains a snapshot of the script. |
2837 * \param buffer_len Length of the passed in buffer. | 2840 * \param buffer_len Length of the passed in buffer. |
2838 * | 2841 * |
2839 * \return If no error occurs, the Library object corresponding to the root | 2842 * \return If no error occurs, the Library object corresponding to the root |
2840 * script is returned. Otherwise an error handle is returned. | 2843 * script is returned. Otherwise an error handle is returned. |
2841 */ | 2844 */ |
2842 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 2845 DART_EXPORT Dart_Handle |
2843 intptr_t buffer_len); | 2846 Dart_LoadScriptFromSnapshot(const uint8_t* script_snapshot_buffer, |
| 2847 intptr_t script_snapshot_size); |
2844 | 2848 |
2845 /** | 2849 /** |
2846 * Loads a dart application via an in-memory kernel program. | 2850 * Loads a dart application via an in-memory kernel program. |
2847 * | 2851 * |
2848 * \param kernel_program The kernel program obtained via | 2852 * \param kernel_program The kernel program obtained via |
2849 * `Dart_ReadKernelBinary`. | 2853 * `Dart_ReadKernelBinary`. |
2850 * | 2854 * |
2851 * The VM will take ownership of the `kernel_program` object. | 2855 * The VM will take ownership of the `kernel_program` object. |
2852 * | 2856 * |
2853 * \return If no error occurs, the Library object corresponding to the root | 2857 * \return If no error occurs, the Library object corresponding to the root |
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3211 Dart_Precompile(Dart_QualifiedFunctionName entry_points[], | 3215 Dart_Precompile(Dart_QualifiedFunctionName entry_points[], |
3212 uint8_t* jit_feedback, | 3216 uint8_t* jit_feedback, |
3213 intptr_t jit_feedback_length); | 3217 intptr_t jit_feedback_length); |
3214 | 3218 |
3215 | 3219 |
3216 /** | 3220 /** |
3217 * Creates a precompiled snapshot. | 3221 * Creates a precompiled snapshot. |
3218 * - A root library must have been loaded. | 3222 * - A root library must have been loaded. |
3219 * - Dart_Precompile must have been called. | 3223 * - Dart_Precompile must have been called. |
3220 * | 3224 * |
3221 * Outputs an assembly file defining the symbols kVmIsolateSnapshot, | 3225 * Outputs an assembly file defining the symbols |
3222 * kIsolateSnapshot, kInstructionsSnapshot and kDataSnapshot. The assembly | 3226 * - kDartVmSnapshotData |
3223 * should be compiled as a static or shared library and linked or loaded by the | 3227 * - kDartVmSnapshotInstructions |
3224 * embedder. | 3228 * - kDartIsolateSnapshotData |
| 3229 * - kDartIsolateSnapshotInstructions |
| 3230 * |
| 3231 * The assembly should be compiled as a static or shared library and linked or |
| 3232 * loaded by the embedder. |
3225 * Running this snapshot requires a VM compiled with DART_PRECOMPILED_SNAPSHOT. | 3233 * Running this snapshot requires a VM compiled with DART_PRECOMPILED_SNAPSHOT. |
3226 * The kVmIsolateSnapshot, kInstructionsSnapshot and kDataSnapshot should be | 3234 * The kDartVmSnapshotData and kDartVmSnapshotInstructions should be passed to |
3227 * passed as arguments to Dart_Initialize. The kIsolateSnapshot snapshot should | 3235 * Dart_Initialize. The kDartIsolateSnapshotData and |
3228 * be passed to Dart_CreateIsolate. | 3236 * kDartIsoalteSnapshotInstructions should be passed to Dart_CreateIsolate. |
3229 * | 3237 * |
3230 * The buffers are scope allocated and are only valid until the next call to | 3238 * The buffers are scope allocated and are only valid until the next call to |
3231 * Dart_ExitScope. | 3239 * Dart_ExitScope. |
3232 * | 3240 * |
3233 * \return A valid handle if no error occurs during the operation. | 3241 * \return A valid handle if no error occurs during the operation. |
3234 */ | 3242 */ |
3235 DART_EXPORT Dart_Handle | 3243 DART_EXPORT Dart_Handle |
3236 Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer, | 3244 Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer, |
3237 intptr_t* assembly_size); | 3245 intptr_t* assembly_size); |
3238 | 3246 |
3239 | 3247 |
3240 /** | 3248 /** |
3241 * Same as Dart_CreateAppAOTSnapshotAsAssembly, except all the pieces are | 3249 * Same as Dart_CreateAppAOTSnapshotAsAssembly, except all the pieces are |
3242 * provided directly as bytes that the embedder can load with mmap. The | 3250 * provided directly as bytes that the embedder can load with mmap. The |
3243 * instructions piece must be loaded with read and execute permissions; the | 3251 * instructions pieces must be loaded with read and execute permissions; the |
3244 * other pieces may be loaded as read-only. | 3252 * other pieces may be loaded as read-only. |
3245 */ | 3253 */ |
3246 DART_EXPORT Dart_Handle | 3254 DART_EXPORT Dart_Handle |
3247 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_isolate_snapshot_buffer, | 3255 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer, |
3248 intptr_t* vm_isolate_snapshot_size, | 3256 intptr_t* vm_snapshot_data_size, |
3249 uint8_t** isolate_snapshot_buffer, | 3257 uint8_t** vm_snapshot_instructions_buffer, |
3250 intptr_t* isolate_snapshot_size, | 3258 intptr_t* vm_snapshot_instructions_size, |
3251 uint8_t** instructions_blob_buffer, | 3259 uint8_t** isolate_snapshot_data_buffer, |
3252 intptr_t* instructions_blob_size, | 3260 intptr_t* isolate_snapshot_data_size, |
3253 uint8_t** rodata_blob_buffer, | 3261 uint8_t** isolate_snapshot_instructions_buffer, |
3254 intptr_t* rodata_blob_size); | 3262 intptr_t* isolate_snapshot_instructions_size); |
3255 | 3263 |
3256 | 3264 |
3257 /** | 3265 /** |
3258 * Creates a snapshot that caches unoptimized code and type feedback for faster | 3266 * Creates a snapshot that caches compiled code and type feedback for faster |
3259 * startup and quicker warmup in a subsequent process. | 3267 * startup and quicker warmup in a subsequent process. |
3260 * | 3268 * |
3261 * Outputs a snapshot in four pieces. The vm isolate snapshot, | 3269 * Outputs a snapshot in two pieces. The pieces should be passed to |
3262 * instructions_blob and rodata_blob should be passed as arguments to | 3270 * Dart_CreateIsolate in a VM using the same VM snapshot pieces used in the |
3263 * Dart_Initialize. The isolate snapshot should be passed to | 3271 * current VM. The instructions piece must be loaded with read and execute |
3264 * Dart_CreateIsolate. The instructions piece must be loaded with execute | 3272 * permissions; the data piece may be loaded as read-only. |
3265 * permissions; the other pieces may loaded as read-only. | |
3266 * | 3273 * |
3267 * - Requires the VM to have been started with --load-deferred-eagerly. | 3274 * - Requires the VM to have been started with --load-deferred-eagerly. |
3268 * - Requires the VM to have not been started with --precompilation. | 3275 * - Requires the VM to have not been started with --precompilation. |
3269 * - Not supported when targeting IA32. | 3276 * - Not supported when targeting IA32 or DBC. |
3270 * - The VM writing the snapshot and the VM reading the snapshot must be the | 3277 * - The VM writing the snapshot and the VM reading the snapshot must be the |
3271 * same version, must be built in the same DEBUG/RELEASE/PRODUCT mode, must | 3278 * same version, must be built in the same DEBUG/RELEASE/PRODUCT mode, must |
3272 * be targeting the same architecture, and must both be in checked mode or | 3279 * be targeting the same architecture, and must both be in checked mode or |
3273 * both in unchecked mode. | 3280 * both in unchecked mode. |
3274 * | 3281 * |
3275 * The buffers are scope allocated and are only valid until the next call to | 3282 * The buffers are scope allocated and are only valid until the next call to |
3276 * Dart_ExitScope. | 3283 * Dart_ExitScope. |
3277 * | 3284 * |
3278 * \return A valid handle if no error occurs during the operation. | 3285 * \return A valid handle if no error occurs during the operation. |
3279 */ | 3286 */ |
3280 DART_EXPORT Dart_Handle | 3287 DART_EXPORT Dart_Handle |
3281 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_buffer, | 3288 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, |
3282 intptr_t* isolate_snapshot_size, | 3289 intptr_t* isolate_snapshot_data_size, |
3283 uint8_t** instructions_blob_buffer, | 3290 uint8_t** isolate_snapshot_instructions_buffer, |
3284 intptr_t* instructions_blob_size, | 3291 intptr_t* isolate_snapshot_instructions_size); |
3285 uint8_t** rodata_blob_buffer, | |
3286 intptr_t* rodata_blob_size); | |
3287 | 3292 |
3288 | 3293 |
3289 /** | 3294 /** |
3290 * Returns whether the VM only supports running from precompiled snapshots and | 3295 * Returns whether the VM only supports running from precompiled snapshots and |
3291 * not from any other kind of snapshot or from source (that is, the VM was | 3296 * not from any other kind of snapshot or from source (that is, the VM was |
3292 * compiled with DART_PRECOMPILED_RUNTIME). | 3297 * compiled with DART_PRECOMPILED_RUNTIME). |
3293 */ | 3298 */ |
3294 DART_EXPORT bool Dart_IsPrecompiledRuntime(); | 3299 DART_EXPORT bool Dart_IsPrecompiledRuntime(); |
3295 | 3300 |
3296 | 3301 |
3297 /** | 3302 /** |
3298 * Print a native stack trace. Used for crash handling. | 3303 * Print a native stack trace. Used for crash handling. |
3299 */ | 3304 */ |
3300 DART_EXPORT void Dart_DumpNativeStackTrace(void* context); | 3305 DART_EXPORT void Dart_DumpNativeStackTrace(void* context); |
3301 | 3306 |
3302 #endif /* INCLUDE_DART_API_H_ */ /* NOLINT */ | 3307 #endif /* INCLUDE_DART_API_H_ */ /* NOLINT */ |
OLD | NEW |