File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -394,6 +394,16 @@ JNIEXPORT jobject JNICALL
394
394
JVM_NewMultiArray (JNIEnv *env, jclass eltClass, jintArray dim);
395
395
396
396
397
+ /*
398
+ * Native memory allocation via NMT.
399
+ */
400
+ typedef uint16_t arena_t ;
401
+ JNIEXPORT arena_t JNICALL JVM_MakeArena (const char *name);
402
+ JNIEXPORT void *JNICALL JVM_ArenaAlloc (size_t size, arena_t a);
403
+ JNIEXPORT void *JNICALL JVM_ArenaRealloc (void *p, size_t size, arena_t a);
404
+ JNIEXPORT void *JNICALL JVM_ArenaCalloc (size_t numelems, size_t elemsize, arena_t a);
405
+ JNIEXPORT void JNICALL JVM_ArenaFree (void * ptr);
406
+
397
407
/*
398
408
* Returns the immediate caller class of the native method invoking
399
409
* JVM_GetCallerClass. The Method.invoke and other frames due to
Original file line number Diff line number Diff line change @@ -3836,3 +3836,33 @@ JVM_END
3836
3836
JVM_LEAF (jboolean, JVM_PrintWarningAtDynamicAgentLoad(void ))
3837
3837
return (EnableDynamicAgentLoading && !FLAG_IS_CMDLINE(EnableDynamicAgentLoading)) ? JNI_TRUE : JNI_FALSE;
3838
3838
JVM_END
3839
+
3840
+ JNIEXPORT arena_t JNICALL
3841
+ JVM_MakeArena (const char *name) {
3842
+ return static_cast <arena_t >(MemTagFactory::tag (name));
3843
+ }
3844
+
3845
+ JNIEXPORT void * JNICALL
3846
+ JVM_ArenaAlloc (size_t size, arena_t arena) {
3847
+ return os::malloc (size, static_cast <MemTag>(arena));
3848
+ }
3849
+
3850
+ JNIEXPORT void * JNICALL
3851
+ JVM_ArenaRealloc (void *p, size_t size, arena_t arena) {
3852
+ return os::realloc (p, size, static_cast <MemTag>(arena));
3853
+ }
3854
+
3855
+ JNIEXPORT void * JNICALL
3856
+ JVM_ArenaCalloc (size_t numelems, size_t elemsize, arena_t arena) {
3857
+ // Overflow check.
3858
+ if (std::numeric_limits<size_t >::max () / elemsize < numelems) {
3859
+ return nullptr ;
3860
+ }
3861
+ size_t total_size = numelems * elemsize;
3862
+ return os::malloc (total_size, static_cast <MemTag>(arena));
3863
+ }
3864
+
3865
+ JNIEXPORT void JNICALL
3866
+ JVM_ArenaFree (void * ptr) {
3867
+ os::free (ptr);
3868
+ }
You can’t perform that action at this time.
0 commit comments