Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Update Dart API headers (#358)
Browse files Browse the repository at this point in the history
* Update Dart API
* Remove unnecessary methods in dartjni.h
  • Loading branch information
HosseinYousefi authored Aug 16, 2023
1 parent 768883d commit efcda83
Show file tree
Hide file tree
Showing 15 changed files with 283 additions and 313 deletions.
2 changes: 1 addition & 1 deletion jni/example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.6.0-dev.2"
version: "0.6.0-wip.2"
js:
dependency: transitive
description:
Expand Down
3 changes: 0 additions & 3 deletions jni/ffigen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ functions:
- 'to_global_ref_result'
- 'wait_for'
# keep-sorted end
# Native functions in Java. No need to call them from Dart.
- 'Java_com_github_dart_1lang_jni_PortContinuation__1resumeWith'
- 'Java_com_github_dart_1lang_jni_PortProxy__1invoke'
structs:
exclude:
- 'JniContext'
Expand Down
20 changes: 0 additions & 20 deletions jni/src/dartjni.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,30 +422,10 @@ FFI_PLUGIN_EXPORT intptr_t InitDartApiDL(void* data);

FFI_PLUGIN_EXPORT void resultFor(CallbackResult* result, jobject object);

JNIEXPORT void JNICALL
Java_com_github_dart_1lang_jni_PortContinuation__1resumeWith(JNIEnv* env,
jobject thiz,
jlong port,
jobject result);
FFI_PLUGIN_EXPORT
JniResult PortContinuation__ctor(int64_t j);

FFI_PLUGIN_EXPORT
JniResult PortProxy__newInstance(jobject binaryName,
int64_t port,
int64_t functionPtr);

JNIEXPORT jobjectArray JNICALL
Java_com_github_dart_1lang_jni_PortProxy__1invoke(JNIEnv* env,
jobject thiz,
jlong port,
jlong threadId,
jlong functionPtr,
jobject proxy,
jstring methodDescriptor,
jobjectArray args);

JNIEXPORT void JNICALL
Java_com_github_dart_1lang_jni_PortProxy__1cleanUp(JNIEnv* env,
jobject thiz,
jlong resultPtr);
181 changes: 134 additions & 47 deletions jni/src/include/dart_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <inttypes.h>
#include <stdbool.h>

#if defined(__Fuchsia__)
#include <zircon/types.h>
#endif

#ifdef __cplusplus
#define DART_EXTERN_C extern "C"
#else
Expand Down Expand Up @@ -849,7 +853,7 @@ typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(void);
* The current version of the Dart_InitializeFlags. Should be incremented every
* time Dart_InitializeFlags changes in a binary incompatible way.
*/
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000007)
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000008)

/** Forward declaration */
struct Dart_CodeObserver;
Expand Down Expand Up @@ -992,6 +996,15 @@ typedef struct {
* Kernel blob unregistration callback function. See Dart_UnregisterKernelBlobCallback.
*/
Dart_UnregisterKernelBlobCallback unregister_kernel_blob;

#if defined(__Fuchsia__)
/**
* The resource needed to use zx_vmo_replace_as_executable. Can be
* ZX_HANDLE_INVALID if the process has ambient-replace-as-executable or if
* executable memory is not needed (e.g., this is an AOT runtime).
*/
zx_handle_t vmex_resource;
#endif
} Dart_InitializeParams;

/**
Expand Down Expand Up @@ -1105,7 +1118,7 @@ Dart_CreateIsolateGroup(const char* script_uri,
* shutdown (may be NULL).
* \param cleanup_callback A callback to be called when the isolate is being
* cleaned up (may be NULL).
* \param isolate_data The embedder-specific data associated with this isolate.
* \param child_isolate_data The embedder-specific data associated with this isolate.
* \param error Set to NULL if creation is successful, set to an error
* message otherwise. The caller is responsible for calling free() on the
* error message.
Expand Down Expand Up @@ -1210,7 +1223,7 @@ DART_EXPORT void* Dart_CurrentIsolateGroupData(void);
* It is the responsibility of the caller to free the returned ID.
*/
typedef int64_t Dart_IsolateGroupId;
DART_EXPORT Dart_IsolateGroupId Dart_CurrentIsolateGroupId();
DART_EXPORT Dart_IsolateGroupId Dart_CurrentIsolateGroupId(void);

/**
* Returns the callback data associated with the specified isolate group. This
Expand All @@ -1228,6 +1241,17 @@ DART_EXPORT void* Dart_IsolateGroupData(Dart_Isolate isolate);
*/
DART_EXPORT Dart_Handle Dart_DebugName(void);

/**
* Returns the debugging name for the current isolate.
*
* This name is unique to each isolate and should only be used to make
* debugging messages more comprehensible.
*
* The returned string is scope allocated and is only valid until the next call
* to Dart_ExitScope.
*/
DART_EXPORT const char* Dart_DebugNameToCString(void);

/**
* Returns the ID for an isolate which is used to query the service protocol.
*
Expand Down Expand Up @@ -1270,6 +1294,79 @@ DART_EXPORT void Dart_KillIsolate(Dart_Isolate isolate);
*/
DART_EXPORT void Dart_NotifyIdle(int64_t deadline);

typedef void (*Dart_HeapSamplingReportCallback)(void* context,
void* data);

typedef void* (*Dart_HeapSamplingCreateCallback)(
Dart_Isolate isolate,
Dart_IsolateGroup isolate_group,
const char* cls_name,
intptr_t allocation_size);
typedef void (*Dart_HeapSamplingDeleteCallback)(void* data);

/**
* Starts the heap sampling profiler for each thread in the VM.
*/
DART_EXPORT void Dart_EnableHeapSampling(void);

/*
* Stops the heap sampling profiler for each thread in the VM.
*/
DART_EXPORT void Dart_DisableHeapSampling(void);

/* Registers callbacks are invoked once per sampled allocation upon object
* allocation and garbage collection.
*
* |create_callback| can be used to associate additional data with the sampled
* allocation, such as a stack trace. This data pointer will be passed to
* |delete_callback| to allow for proper disposal when the object associated
* with the allocation sample is collected.
*
* The provided callbacks must not call into the VM and should do as little
* work as possible to avoid performance penalities during object allocation and
* garbage collection.
*
* NOTE: It is a fatal error to set either callback to null once they have been
* initialized.
*/
DART_EXPORT void Dart_RegisterHeapSamplingCallback(
Dart_HeapSamplingCreateCallback create_callback,
Dart_HeapSamplingDeleteCallback delete_callback);

/*
* Reports the surviving allocation samples for all live isolate groups in the
* VM.
*
* When the callback is invoked:
* - |context| will be the context object provided when invoking
* |Dart_ReportSurvivingAllocations|. This can be safely set to null if not
* required.
* - |heap_size| will be equal to the size of the allocated object associated
* with the sample.
* - |cls_name| will be a C String representing
* the class name of the allocated object. This string is valid for the
* duration of the call to Dart_ReportSurvivingAllocations and can be
* freed by the VM at any point after the method returns.
* - |data| will be set to the data associated with the sample by
* |Dart_HeapSamplingCreateCallback|.
*
* If |force_gc| is true, a full GC will be performed before reporting the
* allocations.
*/
DART_EXPORT void Dart_ReportSurvivingAllocations(
Dart_HeapSamplingReportCallback callback,
void* context,
bool force_gc);

/*
* Sets the average heap sampling rate based on a number of |bytes| for each
* thread.
*
* In other words, approximately every |bytes| allocated will create a sample.
* Defaults to 512 KiB.
*/
DART_EXPORT void Dart_SetHeapSamplingPeriod(intptr_t bytes);

/**
* Notifies the VM that the embedder expects the application's working set has
* recently shrunk significantly and is not expected to rise in the near future.
Expand Down Expand Up @@ -1328,7 +1425,7 @@ DART_EXPORT void Dart_StartProfiling(void);
/**
* Stops the CPU sampling profiler.
*
* Note that some profile samples might still be taken after this fucntion
* Note that some profile samples might still be taken after this function
* returns due to the asynchronous nature of the implementation on some
* platforms.
*/
Expand Down Expand Up @@ -1663,8 +1760,8 @@ DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_RunLoop(void);
* \param error A non-NULL pointer which will hold an error message if the call
* fails. The error has to be free()ed by the caller.
*
* \return If successful the VM takes owernship of the isolate and takes care
* of its message loop. If not successful the caller retains owernship of the
* \return If successful the VM takes ownership of the isolate and takes care
* of its message loop. If not successful the caller retains ownership of the
* isolate.
*/
DART_EXPORT DART_WARN_UNUSED_RESULT bool Dart_RunLoopAsync(
Expand Down Expand Up @@ -1924,7 +2021,7 @@ DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function);
DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function);

/**
* Determines whether a function handle referes to a static function
* Determines whether a function handle refers to a static function
* of method.
*
* For the purposes of the embedding API, a top-level function is
Expand Down Expand Up @@ -3456,7 +3553,7 @@ DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library);
* \param number_of_type_arguments Number of type arguments.
* For non parametric types the number of type arguments would be 0.
* \param type_arguments Pointer to an array of type arguments.
* For non parameteric types a NULL would be passed in for this argument.
* For non parametric types a NULL would be passed in for this argument.
*
* \return If no error occurs, the type is returned.
* Otherwise an error handle is returned.
Expand All @@ -3475,7 +3572,7 @@ DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library,
* \param number_of_type_arguments Number of type arguments.
* For non parametric types the number of type arguments would be 0.
* \param type_arguments Pointer to an array of type arguments.
* For non parameteric types a NULL would be passed in for this argument.
* For non parametric types a NULL would be passed in for this argument.
*
* \return If no error occurs, the type is returned.
* Otherwise an error handle is returned.
Expand All @@ -3494,7 +3591,7 @@ DART_EXPORT Dart_Handle Dart_GetNullableType(Dart_Handle library,
* \param number_of_type_arguments Number of type arguments.
* For non parametric types the number of type arguments would be 0.
* \param type_arguments Pointer to an array of type arguments.
* For non parameteric types a NULL would be passed in for this argument.
* For non parametric types a NULL would be passed in for this argument.
*
* \return If no error occurs, the type is returned.
* Otherwise an error handle is returned.
Expand Down Expand Up @@ -3598,6 +3695,8 @@ DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library,
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_LoadLibraryFromKernel(const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size);
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
Dart_LoadLibrary(Dart_Handle kernel_buffer);

/**
* Indicates that all outstanding load requests have been satisfied.
Expand Down Expand Up @@ -3730,43 +3829,6 @@ Dart_CompileToKernel(const char* script_uri,
const char* package_config,
Dart_KernelCompilationVerbosityLevel verbosity);

/**
* Compiles the given `script_uri` to a kernel file.
*
* \param platform_kernel A buffer containing the kernel of the platform (e.g.
* `vm_platform_strong.dill`). The VM does not take ownership of this memory.
*
* \param platform_kernel_size The length of the platform_kernel buffer.
*
* \param snapshot_compile Set to `true` when the compilation is for a snapshot.
* This is used by the frontend to determine if compilation related information
* should be printed to console (e.g., null safety mode).
*
* \param null_safety Provides null-safety mode setting for the compiler.
*
* \param verbosity Specifies the logging behavior of the kernel compilation
* service.
*
* \return Returns the result of the compilation.
*
* On a successful compilation the returned [Dart_KernelCompilationResult] has
* a status of [Dart_KernelCompilationStatus_Ok] and the `kernel`/`kernel_size`
* fields are set. The caller takes ownership of the malloc()ed buffer.
*
* On a failed compilation the `error` might be set describing the reason for
* the failed compilation. The caller takes ownership of the malloc()ed
* error.
*/
DART_EXPORT Dart_KernelCompilationResult
Dart_CompileToKernelWithGivenNullsafety(
const char* script_uri,
const uint8_t* platform_kernel,
const intptr_t platform_kernel_size,
bool snapshot_compile,
const char* package_config,
const bool null_safety,
Dart_KernelCompilationVerbosityLevel verbosity);

typedef struct {
const char* uri;
const char* source;
Expand Down Expand Up @@ -4095,4 +4157,29 @@ DART_EXPORT void Dart_DumpNativeStackTrace(void* context);
*/
DART_EXPORT void Dart_PrepareToAbort(void);

/**
* Callback provided by the embedder that is used by the VM to
* produce footnotes appended to DWARF stack traces.
*
* Whenever VM formats a stack trace as a string it would call this callback
* passing raw program counters for each frame in the stack trace.
*
* Embedder can then return a string which if not-null will be appended to the
* formatted stack trace.
*
* Returned string is expected to be `malloc()` allocated. VM takes ownership
* of the returned string and will `free()` it.
*
* \param addresses raw program counter addresses for each frame
* \param count number of elements in the addresses array
*/
typedef char* (*Dart_DwarfStackTraceFootnoteCallback)(void* addresses[],
intptr_t count);

/**
* Configure DWARF stack trace footnote callback.
*/
DART_EXPORT void Dart_SetDwarfStackTraceFootnoteCallback(
Dart_DwarfStackTraceFootnoteCallback callback);

#endif /* INCLUDE_DART_API_H_ */ /* NOLINT */
10 changes: 8 additions & 2 deletions jni/src/include/dart_api_dl.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ DART_EXPORT intptr_t Dart_InitializeApiDL(void* data);
// DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION.
//
// Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types
// to trigger compile-time errors if the sybols in those files are updated
// to trigger compile-time errors if the symbols in those files are updated
// without updating these.
//
// Function return and argument types, and typedefs are carbon copied. Structs
Expand Down Expand Up @@ -90,14 +90,20 @@ typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id,
F(Dart_UpdateFinalizableExternalSize, void, \
(Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \
intptr_t external_allocation_size)) \
/* Isolates */ \
F(Dart_CurrentIsolate, Dart_Isolate, (void)) \
F(Dart_ExitIsolate, void, (void)) \
F(Dart_EnterIsolate, void, (Dart_Isolate)) \
/* Dart_Port */ \
F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \
F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \
F(Dart_SendPortGetId, Dart_Handle, \
(Dart_Handle port, Dart_Port_DL * port_id)) \
/* Scopes */ \
F(Dart_EnterScope, void, (void)) \
F(Dart_ExitScope, void, (void))
F(Dart_ExitScope, void, (void)) \
/* Objects */ \
F(Dart_IsNull, bool, (Dart_Handle))

#define DART_API_ALL_DL_SYMBOLS(F) \
DART_NATIVE_API_DL_SYMBOLS(F) \
Expand Down
6 changes: 4 additions & 2 deletions jni/src/include/dart_native_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ typedef enum {
Dart_CObject_kArray,
Dart_CObject_kTypedData,
Dart_CObject_kExternalTypedData,
Dart_CObject_kUnmodifiableExternalTypedData,
Dart_CObject_kSendPort,
Dart_CObject_kCapability,
Dart_CObject_kNativePointer,
Dart_CObject_kUnsupported,
Dart_CObject_kUnmodifiableExternalTypedData,
Dart_CObject_kNumberOfTypes
} Dart_CObject_Type;
// This enum is versioned by DART_API_DL_MAJOR_VERSION, only add at the end
// and bump the DART_API_DL_MINOR_VERSION.

typedef struct _Dart_CObject {
Dart_CObject_Type type;
Expand All @@ -65,7 +67,7 @@ typedef struct _Dart_CObject {
int32_t as_int32;
int64_t as_int64;
double as_double;
char* as_string;
const char* as_string;
struct {
Dart_Port id;
Dart_Port origin_id;
Expand Down
Loading

0 comments on commit efcda83

Please sign in to comment.