Skip to content

Commit dc972ba

Browse files
[jnigen] Update Dart API headers (#358)
* Update Dart API * Remove unnecessary methods in dartjni.h
1 parent f7fa481 commit dc972ba

File tree

15 files changed

+283
-313
lines changed

15 files changed

+283
-313
lines changed

pkgs/jni/example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ packages:
200200
path: ".."
201201
relative: true
202202
source: path
203-
version: "0.6.0-dev.2"
203+
version: "0.6.0-wip.2"
204204
js:
205205
dependency: transitive
206206
description:

pkgs/jni/ffigen.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,6 @@ functions:
5757
- 'to_global_ref_result'
5858
- 'wait_for'
5959
# keep-sorted end
60-
# Native functions in Java. No need to call them from Dart.
61-
- 'Java_com_github_dart_1lang_jni_PortContinuation__1resumeWith'
62-
- 'Java_com_github_dart_1lang_jni_PortProxy__1invoke'
6360
structs:
6461
exclude:
6562
- 'JniContext'

pkgs/jni/src/dartjni.h

-20
Original file line numberDiff line numberDiff line change
@@ -422,30 +422,10 @@ FFI_PLUGIN_EXPORT intptr_t InitDartApiDL(void* data);
422422

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

425-
JNIEXPORT void JNICALL
426-
Java_com_github_dart_1lang_jni_PortContinuation__1resumeWith(JNIEnv* env,
427-
jobject thiz,
428-
jlong port,
429-
jobject result);
430425
FFI_PLUGIN_EXPORT
431426
JniResult PortContinuation__ctor(int64_t j);
432427

433428
FFI_PLUGIN_EXPORT
434429
JniResult PortProxy__newInstance(jobject binaryName,
435430
int64_t port,
436431
int64_t functionPtr);
437-
438-
JNIEXPORT jobjectArray JNICALL
439-
Java_com_github_dart_1lang_jni_PortProxy__1invoke(JNIEnv* env,
440-
jobject thiz,
441-
jlong port,
442-
jlong threadId,
443-
jlong functionPtr,
444-
jobject proxy,
445-
jstring methodDescriptor,
446-
jobjectArray args);
447-
448-
JNIEXPORT void JNICALL
449-
Java_com_github_dart_1lang_jni_PortProxy__1cleanUp(JNIEnv* env,
450-
jobject thiz,
451-
jlong resultPtr);

pkgs/jni/src/include/dart_api.h

+134-47
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <inttypes.h>
2626
#include <stdbool.h>
2727

28+
#if defined(__Fuchsia__)
29+
#include <zircon/types.h>
30+
#endif
31+
2832
#ifdef __cplusplus
2933
#define DART_EXTERN_C extern "C"
3034
#else
@@ -849,7 +853,7 @@ typedef Dart_Handle (*Dart_GetVMServiceAssetsArchive)(void);
849853
* The current version of the Dart_InitializeFlags. Should be incremented every
850854
* time Dart_InitializeFlags changes in a binary incompatible way.
851855
*/
852-
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000007)
856+
#define DART_INITIALIZE_PARAMS_CURRENT_VERSION (0x00000008)
853857

854858
/** Forward declaration */
855859
struct Dart_CodeObserver;
@@ -992,6 +996,15 @@ typedef struct {
992996
* Kernel blob unregistration callback function. See Dart_UnregisterKernelBlobCallback.
993997
*/
994998
Dart_UnregisterKernelBlobCallback unregister_kernel_blob;
999+
1000+
#if defined(__Fuchsia__)
1001+
/**
1002+
* The resource needed to use zx_vmo_replace_as_executable. Can be
1003+
* ZX_HANDLE_INVALID if the process has ambient-replace-as-executable or if
1004+
* executable memory is not needed (e.g., this is an AOT runtime).
1005+
*/
1006+
zx_handle_t vmex_resource;
1007+
#endif
9951008
} Dart_InitializeParams;
9961009

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

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

1244+
/**
1245+
* Returns the debugging name for the current isolate.
1246+
*
1247+
* This name is unique to each isolate and should only be used to make
1248+
* debugging messages more comprehensible.
1249+
*
1250+
* The returned string is scope allocated and is only valid until the next call
1251+
* to Dart_ExitScope.
1252+
*/
1253+
DART_EXPORT const char* Dart_DebugNameToCString(void);
1254+
12311255
/**
12321256
* Returns the ID for an isolate which is used to query the service protocol.
12331257
*
@@ -1270,6 +1294,79 @@ DART_EXPORT void Dart_KillIsolate(Dart_Isolate isolate);
12701294
*/
12711295
DART_EXPORT void Dart_NotifyIdle(int64_t deadline);
12721296

1297+
typedef void (*Dart_HeapSamplingReportCallback)(void* context,
1298+
void* data);
1299+
1300+
typedef void* (*Dart_HeapSamplingCreateCallback)(
1301+
Dart_Isolate isolate,
1302+
Dart_IsolateGroup isolate_group,
1303+
const char* cls_name,
1304+
intptr_t allocation_size);
1305+
typedef void (*Dart_HeapSamplingDeleteCallback)(void* data);
1306+
1307+
/**
1308+
* Starts the heap sampling profiler for each thread in the VM.
1309+
*/
1310+
DART_EXPORT void Dart_EnableHeapSampling(void);
1311+
1312+
/*
1313+
* Stops the heap sampling profiler for each thread in the VM.
1314+
*/
1315+
DART_EXPORT void Dart_DisableHeapSampling(void);
1316+
1317+
/* Registers callbacks are invoked once per sampled allocation upon object
1318+
* allocation and garbage collection.
1319+
*
1320+
* |create_callback| can be used to associate additional data with the sampled
1321+
* allocation, such as a stack trace. This data pointer will be passed to
1322+
* |delete_callback| to allow for proper disposal when the object associated
1323+
* with the allocation sample is collected.
1324+
*
1325+
* The provided callbacks must not call into the VM and should do as little
1326+
* work as possible to avoid performance penalities during object allocation and
1327+
* garbage collection.
1328+
*
1329+
* NOTE: It is a fatal error to set either callback to null once they have been
1330+
* initialized.
1331+
*/
1332+
DART_EXPORT void Dart_RegisterHeapSamplingCallback(
1333+
Dart_HeapSamplingCreateCallback create_callback,
1334+
Dart_HeapSamplingDeleteCallback delete_callback);
1335+
1336+
/*
1337+
* Reports the surviving allocation samples for all live isolate groups in the
1338+
* VM.
1339+
*
1340+
* When the callback is invoked:
1341+
* - |context| will be the context object provided when invoking
1342+
* |Dart_ReportSurvivingAllocations|. This can be safely set to null if not
1343+
* required.
1344+
* - |heap_size| will be equal to the size of the allocated object associated
1345+
* with the sample.
1346+
* - |cls_name| will be a C String representing
1347+
* the class name of the allocated object. This string is valid for the
1348+
* duration of the call to Dart_ReportSurvivingAllocations and can be
1349+
* freed by the VM at any point after the method returns.
1350+
* - |data| will be set to the data associated with the sample by
1351+
* |Dart_HeapSamplingCreateCallback|.
1352+
*
1353+
* If |force_gc| is true, a full GC will be performed before reporting the
1354+
* allocations.
1355+
*/
1356+
DART_EXPORT void Dart_ReportSurvivingAllocations(
1357+
Dart_HeapSamplingReportCallback callback,
1358+
void* context,
1359+
bool force_gc);
1360+
1361+
/*
1362+
* Sets the average heap sampling rate based on a number of |bytes| for each
1363+
* thread.
1364+
*
1365+
* In other words, approximately every |bytes| allocated will create a sample.
1366+
* Defaults to 512 KiB.
1367+
*/
1368+
DART_EXPORT void Dart_SetHeapSamplingPeriod(intptr_t bytes);
1369+
12731370
/**
12741371
* Notifies the VM that the embedder expects the application's working set has
12751372
* recently shrunk significantly and is not expected to rise in the near future.
@@ -1328,7 +1425,7 @@ DART_EXPORT void Dart_StartProfiling(void);
13281425
/**
13291426
* Stops the CPU sampling profiler.
13301427
*
1331-
* Note that some profile samples might still be taken after this fucntion
1428+
* Note that some profile samples might still be taken after this function
13321429
* returns due to the asynchronous nature of the implementation on some
13331430
* platforms.
13341431
*/
@@ -1663,8 +1760,8 @@ DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle Dart_RunLoop(void);
16631760
* \param error A non-NULL pointer which will hold an error message if the call
16641761
* fails. The error has to be free()ed by the caller.
16651762
*
1666-
* \return If successful the VM takes owernship of the isolate and takes care
1667-
* of its message loop. If not successful the caller retains owernship of the
1763+
* \return If successful the VM takes ownership of the isolate and takes care
1764+
* of its message loop. If not successful the caller retains ownership of the
16681765
* isolate.
16691766
*/
16701767
DART_EXPORT DART_WARN_UNUSED_RESULT bool Dart_RunLoopAsync(
@@ -1924,7 +2021,7 @@ DART_EXPORT Dart_Handle Dart_FunctionName(Dart_Handle function);
19242021
DART_EXPORT Dart_Handle Dart_FunctionOwner(Dart_Handle function);
19252022

19262023
/**
1927-
* Determines whether a function handle referes to a static function
2024+
* Determines whether a function handle refers to a static function
19282025
* of method.
19292026
*
19302027
* For the purposes of the embedding API, a top-level function is
@@ -3456,7 +3553,7 @@ DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library);
34563553
* \param number_of_type_arguments Number of type arguments.
34573554
* For non parametric types the number of type arguments would be 0.
34583555
* \param type_arguments Pointer to an array of type arguments.
3459-
* For non parameteric types a NULL would be passed in for this argument.
3556+
* For non parametric types a NULL would be passed in for this argument.
34603557
*
34613558
* \return If no error occurs, the type is returned.
34623559
* Otherwise an error handle is returned.
@@ -3475,7 +3572,7 @@ DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library,
34753572
* \param number_of_type_arguments Number of type arguments.
34763573
* For non parametric types the number of type arguments would be 0.
34773574
* \param type_arguments Pointer to an array of type arguments.
3478-
* For non parameteric types a NULL would be passed in for this argument.
3575+
* For non parametric types a NULL would be passed in for this argument.
34793576
*
34803577
* \return If no error occurs, the type is returned.
34813578
* Otherwise an error handle is returned.
@@ -3494,7 +3591,7 @@ DART_EXPORT Dart_Handle Dart_GetNullableType(Dart_Handle library,
34943591
* \param number_of_type_arguments Number of type arguments.
34953592
* For non parametric types the number of type arguments would be 0.
34963593
* \param type_arguments Pointer to an array of type arguments.
3497-
* For non parameteric types a NULL would be passed in for this argument.
3594+
* For non parametric types a NULL would be passed in for this argument.
34983595
*
34993596
* \return If no error occurs, the type is returned.
35003597
* Otherwise an error handle is returned.
@@ -3598,6 +3695,8 @@ DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library,
35983695
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
35993696
Dart_LoadLibraryFromKernel(const uint8_t* kernel_buffer,
36003697
intptr_t kernel_buffer_size);
3698+
DART_EXPORT DART_WARN_UNUSED_RESULT Dart_Handle
3699+
Dart_LoadLibrary(Dart_Handle kernel_buffer);
36013700

36023701
/**
36033702
* Indicates that all outstanding load requests have been satisfied.
@@ -3730,43 +3829,6 @@ Dart_CompileToKernel(const char* script_uri,
37303829
const char* package_config,
37313830
Dart_KernelCompilationVerbosityLevel verbosity);
37323831

3733-
/**
3734-
* Compiles the given `script_uri` to a kernel file.
3735-
*
3736-
* \param platform_kernel A buffer containing the kernel of the platform (e.g.
3737-
* `vm_platform_strong.dill`). The VM does not take ownership of this memory.
3738-
*
3739-
* \param platform_kernel_size The length of the platform_kernel buffer.
3740-
*
3741-
* \param snapshot_compile Set to `true` when the compilation is for a snapshot.
3742-
* This is used by the frontend to determine if compilation related information
3743-
* should be printed to console (e.g., null safety mode).
3744-
*
3745-
* \param null_safety Provides null-safety mode setting for the compiler.
3746-
*
3747-
* \param verbosity Specifies the logging behavior of the kernel compilation
3748-
* service.
3749-
*
3750-
* \return Returns the result of the compilation.
3751-
*
3752-
* On a successful compilation the returned [Dart_KernelCompilationResult] has
3753-
* a status of [Dart_KernelCompilationStatus_Ok] and the `kernel`/`kernel_size`
3754-
* fields are set. The caller takes ownership of the malloc()ed buffer.
3755-
*
3756-
* On a failed compilation the `error` might be set describing the reason for
3757-
* the failed compilation. The caller takes ownership of the malloc()ed
3758-
* error.
3759-
*/
3760-
DART_EXPORT Dart_KernelCompilationResult
3761-
Dart_CompileToKernelWithGivenNullsafety(
3762-
const char* script_uri,
3763-
const uint8_t* platform_kernel,
3764-
const intptr_t platform_kernel_size,
3765-
bool snapshot_compile,
3766-
const char* package_config,
3767-
const bool null_safety,
3768-
Dart_KernelCompilationVerbosityLevel verbosity);
3769-
37703832
typedef struct {
37713833
const char* uri;
37723834
const char* source;
@@ -4095,4 +4157,29 @@ DART_EXPORT void Dart_DumpNativeStackTrace(void* context);
40954157
*/
40964158
DART_EXPORT void Dart_PrepareToAbort(void);
40974159

4160+
/**
4161+
* Callback provided by the embedder that is used by the VM to
4162+
* produce footnotes appended to DWARF stack traces.
4163+
*
4164+
* Whenever VM formats a stack trace as a string it would call this callback
4165+
* passing raw program counters for each frame in the stack trace.
4166+
*
4167+
* Embedder can then return a string which if not-null will be appended to the
4168+
* formatted stack trace.
4169+
*
4170+
* Returned string is expected to be `malloc()` allocated. VM takes ownership
4171+
* of the returned string and will `free()` it.
4172+
*
4173+
* \param addresses raw program counter addresses for each frame
4174+
* \param count number of elements in the addresses array
4175+
*/
4176+
typedef char* (*Dart_DwarfStackTraceFootnoteCallback)(void* addresses[],
4177+
intptr_t count);
4178+
4179+
/**
4180+
* Configure DWARF stack trace footnote callback.
4181+
*/
4182+
DART_EXPORT void Dart_SetDwarfStackTraceFootnoteCallback(
4183+
Dart_DwarfStackTraceFootnoteCallback callback);
4184+
40984185
#endif /* INCLUDE_DART_API_H_ */ /* NOLINT */

pkgs/jni/src/include/dart_api_dl.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ DART_EXPORT intptr_t Dart_InitializeApiDL(void* data);
2929
// DART_API_DL_MAJOR_VERSION and DART_API_DL_MINOR_VERSION.
3030
//
3131
// Verbatim copy of `dart_native_api.h` and `dart_api.h` symbol names and types
32-
// to trigger compile-time errors if the sybols in those files are updated
32+
// to trigger compile-time errors if the symbols in those files are updated
3333
// without updating these.
3434
//
3535
// Function return and argument types, and typedefs are carbon copied. Structs
@@ -90,14 +90,20 @@ typedef void (*Dart_NativeMessageHandler_DL)(Dart_Port_DL dest_port_id,
9090
F(Dart_UpdateFinalizableExternalSize, void, \
9191
(Dart_FinalizableHandle object, Dart_Handle strong_ref_to_object, \
9292
intptr_t external_allocation_size)) \
93+
/* Isolates */ \
94+
F(Dart_CurrentIsolate, Dart_Isolate, (void)) \
95+
F(Dart_ExitIsolate, void, (void)) \
96+
F(Dart_EnterIsolate, void, (Dart_Isolate)) \
9397
/* Dart_Port */ \
9498
F(Dart_Post, bool, (Dart_Port_DL port_id, Dart_Handle object)) \
9599
F(Dart_NewSendPort, Dart_Handle, (Dart_Port_DL port_id)) \
96100
F(Dart_SendPortGetId, Dart_Handle, \
97101
(Dart_Handle port, Dart_Port_DL * port_id)) \
98102
/* Scopes */ \
99103
F(Dart_EnterScope, void, (void)) \
100-
F(Dart_ExitScope, void, (void))
104+
F(Dart_ExitScope, void, (void)) \
105+
/* Objects */ \
106+
F(Dart_IsNull, bool, (Dart_Handle))
101107

102108
#define DART_API_ALL_DL_SYMBOLS(F) \
103109
DART_NATIVE_API_DL_SYMBOLS(F) \

pkgs/jni/src/include/dart_native_api.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@ typedef enum {
5050
Dart_CObject_kArray,
5151
Dart_CObject_kTypedData,
5252
Dart_CObject_kExternalTypedData,
53-
Dart_CObject_kUnmodifiableExternalTypedData,
5453
Dart_CObject_kSendPort,
5554
Dart_CObject_kCapability,
5655
Dart_CObject_kNativePointer,
5756
Dart_CObject_kUnsupported,
57+
Dart_CObject_kUnmodifiableExternalTypedData,
5858
Dart_CObject_kNumberOfTypes
5959
} Dart_CObject_Type;
60+
// This enum is versioned by DART_API_DL_MAJOR_VERSION, only add at the end
61+
// and bump the DART_API_DL_MINOR_VERSION.
6062

6163
typedef struct _Dart_CObject {
6264
Dart_CObject_Type type;
@@ -65,7 +67,7 @@ typedef struct _Dart_CObject {
6567
int32_t as_int32;
6668
int64_t as_int64;
6769
double as_double;
68-
char* as_string;
70+
const char* as_string;
6971
struct {
7072
Dart_Port id;
7173
Dart_Port origin_id;

0 commit comments

Comments
 (0)