Skip to content

Commit

Permalink
JVM Image Fixes (eclipse-openj9#20)
Browse files Browse the repository at this point in the history
* Updated JVMImageHeader and fixed reading from file

* Formatting fixup

* Moved the header's buffer to the stack

Signed-off-by: Brady Jessup <[email protected]>
  • Loading branch information
Ershany-IBM authored Jun 27, 2019
1 parent f433aec commit 3ae4fdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion runtime/oti/jvmimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct JVMImageHeader;
*/
typedef struct JVMImageHeader {
UDATA imageSize; /* image size in bytes */
uintptr_t heapAddress;
uintptr_t imageAddress;
J9WSRP classLoaderTable;
J9WSRP classSegmentTable;
J9WSRP classPathEntryTable;
Expand Down
15 changes: 8 additions & 7 deletions runtime/vm/JVMImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ JVMImage::~JVMImage()
{
PORT_ACCESS_FROM_JAVAVM(_vm);

j9mem_free_memory((void*)_jvmImageHeader);
j9mem_free_memory((void *)_jvmImageHeader);
}

bool
Expand Down Expand Up @@ -122,6 +122,7 @@ JVMImage::allocateImageMemory(UDATA size)
}

_jvmImageHeader->imageSize = size;
_jvmImageHeader->imageAddress = (uintptr_t)_jvmImageHeader;

return _jvmImageHeader;
}
Expand All @@ -143,8 +144,6 @@ JVMImage::initializeHeap(void)
return NULL;
}

_jvmImageHeader->heapAddress = (uintptr_t)_heap;

return _heap;
}

Expand Down Expand Up @@ -329,15 +328,17 @@ JVMImage::readImageFromFile(void)
}

/* Read image header then mmap the rest of the image (heap) into memory */
omrfile_read(fileDescriptor, (void *)_jvmImageHeader, sizeof(JVMImageHeader));
/* TODO: Should only read imageAddress and size because that is the only data we need for mmap */
JVMImageHeader imageHeaderBuffer;
omrfile_read(fileDescriptor, (void *)&imageHeaderBuffer, sizeof(JVMImageHeader));
uint64_t fileSize = omrfile_flength(fileDescriptor);
if (_jvmImageHeader->imageSize != fileSize) {
if (imageHeaderBuffer.imageSize != fileSize) {
return false;
}

_jvmImageHeader = (JVMImageHeader *)mmap(
(void *)_jvmImageHeader->heapAddress,
_jvmImageHeader->imageSize,
(void *)imageHeaderBuffer.imageAddress,
imageHeaderBuffer.imageSize,
PROT_READ, MAP_PRIVATE, fileDescriptor, 0);
_heap = (J9Heap *)(_jvmImageHeader + 1);

Expand Down

0 comments on commit 3ae4fdf

Please sign in to comment.