Skip to content

Commit

Permalink
Merge pull request #8 from TobiAjila/classpath
Browse files Browse the repository at this point in the history
Added wrapper for image memory allocate and image memory free
  • Loading branch information
VinoshanT authored Jun 11, 2019
2 parents 2e2db88 + cf46622 commit 7b60c78
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
20 changes: 18 additions & 2 deletions runtime/oti/jvmimage_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@
extern "C" {
#endif

/*
* Allocate memory in heap image
*
* @param size[in] size to allocate
*
* returns pointer to allocated memory on success, NULL on failure
*/
void* mem_allocate_memory(uintptr_t byteAmount);

/*
* Allocate memory in heap image
*
Expand All @@ -41,15 +50,22 @@ extern "C" {
*
* returns pointer to allocated memory on success, NULL on failure
*/
void* image_mem_allocate_memory(struct OMRPortLibrary* portLibrary, uintptr_t byteAmount, const char* callSite, uint32_t category);
void* image_mem_allocate_memory(struct OMRPortLibrary *portLibrary, uintptr_t byteAmount, const char *callSite, uint32_t category);

/*
* Free memory in heap image
*
* @param memoryPointer[in] pointer to address for free
*/
void mem_free_memory(void *memoryPointer);

/*
* Free memory in heap image
*
* @param portLibrary[in] the default port library
* @param memoryPointer[in] pointer to address for free
*/
void image_mem_free_memory(struct OMRPortLibrary* portLibrary, void* memoryPointer);
void image_mem_free_memory(struct OMRPortLibrary *portLibrary, void *memoryPointer);

/*
* Creates and allocates the jvm image and its' heap
Expand Down
20 changes: 17 additions & 3 deletions runtime/vm/JVMImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ create_and_allocate_jvm_image(J9JavaVM *vm)
}

extern "C" void *
image_mem_allocate_memory(struct OMRPortLibrary* portLibrary, uintptr_t byteAmount, const char* callSite, uint32_t category)
image_mem_allocate_memory(struct OMRPortLibrary *portLibrary, uintptr_t byteAmount, const char *callSite, uint32_t category)
{
void *pointer = NULL;

Expand All @@ -196,9 +196,23 @@ image_mem_allocate_memory(struct OMRPortLibrary* portLibrary, uintptr_t byteAmou
return pointer;
}

extern "C" void *
mem_allocate_memory(uintptr_t byteAmount)
{
JVMImage *jvmImage = JVMImage::getInstance();
return image_mem_allocate_memory(jvmImage->getPortLibrary(), byteAmount, J9_GET_CALLSITE(), J9MEM_CATEGORY_CLASSES);
}

extern "C" void
image_mem_free_memory(struct OMRPortLibrary* portLibrary, void* memoryPointer)
image_mem_free_memory(struct OMRPortLibrary *portLibrary, void *memoryPointer)
{
JVMImage *jvmImage = JVMImage::getInstance();
jvmImage->freeSubAllocatedMemory(memoryPointer);
}
}

extern "C" void
mem_free_memory(void *memoryPointer)
{
JVMImage *jvmImage = JVMImage::getInstance();
image_mem_free_memory(jvmImage->getPortLibrary(), memoryPointer);
}

0 comments on commit 7b60c78

Please sign in to comment.