Skip to content

Commit

Permalink
Merge pull request eclipse-openj9#36 from tajila/EB
Browse files Browse the repository at this point in the history
Fix startup and shutdown sequence
  • Loading branch information
tajila authored Aug 22, 2019
2 parents f7fbb7a + 72e3037 commit 0638fa2
Show file tree
Hide file tree
Showing 12 changed files with 345 additions and 109 deletions.
8 changes: 8 additions & 0 deletions runtime/j9vm/jvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,7 @@ typedef struct J9SpecialArguments {
UDATA *argEncoding;
IDATA *ibmMallocTraceSet;
const char *executableJarPath;
char *ramCache;
} J9SpecialArguments;
/**
* Look for special options:
Expand Down Expand Up @@ -1287,6 +1288,8 @@ initialArgumentScan(JavaVMInitArgs *args, J9SpecialArguments *specialArgs)
*(specialArgs->argEncoding) = ARG_ENCODING_UTF;
} else if (0 == strcmp(args->options[argCursor].optionString, VMOPT_XARGENCODINGLATIN)) {
*(specialArgs->argEncoding) = ARG_ENCODING_LATIN;
} else if (0 == strncmp(args->options[argCursor].optionString, VMOPT_XRAMCACHE, sizeof(VMOPT_XRAMCACHE) - 1)) {
specialArgs->ramCache = args->options[argCursor].optionString + strlen(VMOPT_XRAMCACHE);
}
}

Expand Down Expand Up @@ -1760,6 +1763,11 @@ jint JNICALL JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *vm_args) {
launcherArgumentsSize = initialArgumentScan(args, &specialArgs);
localVerboseLevel = specialArgs.localVerboseLevel;

if (NULL != specialArgs.ramCache) {
createParams.flags |= J9_CREATEJAVAVM_RAM_CACHE;
createParams.ramCache = specialArgs.ramCache;
}

if (VERBOSE_INIT == localVerboseLevel) {
createParams.flags |= J9_CREATEJAVAVM_VERBOSE_INIT;
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "j9consts.h"
#include "jvmti.h"
#include "j9javaaccessflags.h"
#include "jvmimageport.h"

#define J9VM_MAX_HIDDEN_FIELDS_PER_CLASS 8

Expand Down Expand Up @@ -5116,7 +5117,7 @@ typedef struct J9JavaVM {
struct J9PortLibrary * portLibrary;
UDATA j2seVersion;
void* zipCachePool;
void* jvmImagePortLibrary;
JVMImagePortLibrary* jvmImagePortLibrary;
char* ramStateFilePath;
struct J9VMInterface vmInterface;
#if defined(J9VM_OPT_HARMONY)
Expand Down
13 changes: 2 additions & 11 deletions runtime/oti/jvmimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct JVMImageSizeAndLocation;
*/
typedef struct JVMImageHeader {
UDATA imageSize; /* image size in bytes */
J9JavaVM *vm;
J9Pool *classLoaderBlocks;
uintptr_t imageAddress;
uintptr_t imageAlignedAddress; /* TODO: Will be removed once PAGE alignment is not needed anymore */
/* TODO: only three main class loaders stored for prototype and quick access. Need to allow user defined classloaders */
Expand All @@ -84,17 +86,6 @@ typedef struct JVMImageHeader {
J9WSRP cInitialVirtualMethod;
} JVMImageHeader;

/*
* Struct containing first three elements of JVMImageHeader
*
* Used for initial read from file. see @ref JVMImage::readImageFromFile
*/
typedef struct JVMImageSizeAndLocation {
UDATA imageSize;
uintptr_t imageAddress;
uintptr_t imageAlignedAddress;
} JVMImageSizeAndLocation;

/* Table structure to walk thorugh registered entries for J9Class, J9ClassLoader, and CPEntries
*
* Needed for fixup during teardown sequence
Expand Down
47 changes: 43 additions & 4 deletions runtime/oti/jvmimage_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,44 @@ void image_mem_free_memory(struct OMRPortLibrary *portLibrary, void *memoryPoint
*
* @return 0 on fail, 1 on success
*/
UDATA initializeJVMImage(J9JavaVM *javaVM);
JVMImagePortLibrary *
initializeJVMImage(J9PortLibrary *portLibrary, BOOLEAN isColdRun, const char* ramCache);

/**
* Initialize JVMImage
*
* @param jvmImagePortLibrary[in] jvmPortLib
* @param javaVM[in] vm token
*/
void
setupJVMImage(JVMImagePortLibrary *jvmImagePortLibrary, J9JavaVM *javaVM);

/**
* Retrieve javaVM from JVm image
*
* @param jvmImagePortLibrary[in] jvmPortLib
* @return vm token
*/
J9JavaVM *
getJ9JavaVMFromJVMImage(JVMImagePortLibrary *jvmImagePortLibrary);

/**
* Retrieve classloader blocks from JVM image
*
* @param javaVM[in] vm token
* @return classLoaderBlocks
*/
J9Pool*
getClassLoaderBlocks(J9JavaVM *javaVM);

/**
* Store classloader blocks in JVM image
*
* @param javaVM[in] vm token
* @return classLoaderBlocks
*/
void
registerClassLoaderBlocks(J9JavaVM *javaVM);

/*
* Registers class loader to one of the three defined class loaders
Expand Down Expand Up @@ -166,14 +203,16 @@ void initializeImageClassLoaderObject(J9JavaVM *javaVM, J9ClassLoader *classLoad
* Frees memory of heap variables and jvmimage instance
* Does not destroy jvmimageheap monitor
*
* @param javaVM[in] the java vm
* @param jvmImagePortLibrary[in] the jvmImagePortlib
*/
void shutdownJVMImage(J9JavaVM *vm);
void shutdownJVMImage(JVMImagePortLibrary *jvmImagePortLibrary);

/*
* Called on cold run to perform fixup of the image heap memory
* Fixup of J9Class, J9ClassLoader, and J9CPEntry performed
*
* TODO should rename this, not clear
*
* @param javaVM[in] the java vm
*/
void teardownJVMImage(J9JavaVM *javaVM);
Expand Down Expand Up @@ -203,4 +242,4 @@ void setInitialVMMethods(J9JavaVM *javaVM, J9Method **cInitialStaticMethod, J9Me
}
#endif

#endif /* jvmimage_api_h */
#endif /* jvmimage_api_h */
2 changes: 1 addition & 1 deletion runtime/oti/jvmimageport.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ typedef struct JVMImagePortLibrary {
#define imem_allocate_memory(param1, category) IMAGE_OMRPORT_FROM_JVMIMAGEPORT(privateImagePortLibrary)->mem_allocate_memory(IMAGE_OMRPORT_FROM_JVMIMAGEPORT(privateImagePortLibrary),param1, J9_GET_CALLSITE(), category)
#define imem_free_memory(param1) IMAGE_OMRPORT_FROM_JVMIMAGEPORT(privateImagePortLibrary)->mem_free_memory(IMAGE_OMRPORT_FROM_JVMIMAGEPORT(privateImagePortLibrary),param1)

#endif
#endif
3 changes: 3 additions & 0 deletions runtime/oti/vm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "j9comp.h"
#include "jni.h"
#include "omrthread.h"
#include "jvmimageport.h"

#ifdef __cplusplus
extern "C" {
Expand All @@ -45,6 +46,7 @@ extern "C" {
#define J9_CREATEJAVAVM_ARGENCODING_LATIN 2
#define J9_CREATEJAVAVM_ARGENCODING_UTF8 4
#define J9_CREATEJAVAVM_ARGENCODING_PLATFORM 8
#define J9_CREATEJAVAVM_RAM_CACHE 16

typedef struct J9CreateJavaVMParams {
UDATA j2seVersion;
Expand All @@ -54,6 +56,7 @@ typedef struct J9CreateJavaVMParams {
J9JavaVM **globalJavaVM;
J9PortLibrary *portLibrary;
UDATA flags;
const char *ramCache;
} J9CreateJavaVMParams;

/* ---------------- FastJNI.cpp ---------------- */
Expand Down
6 changes: 3 additions & 3 deletions runtime/util/cphelp.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ addJarToSystemClassLoaderClassPathEntries(J9JavaVM *vm, const char *filename)
classPathLength += oldEntries[entryIndex].pathLength + 1; /* add 1 for a null character */
}
/* Copy and grow the classPathEntries array */
if (IS_COLD_RUN(vm)) {
if (IS_RAM_CACHE_ON(vm)) {
newEntries = (J9ClassPathEntry *) imem_allocate_memory(sizeof(J9ClassPathEntry) * (entryCount + 1) + classPathLength, J9MEM_CATEGORY_CLASSES);
} else {
newEntries = (J9ClassPathEntry *) j9mem_allocate_memory(sizeof(J9ClassPathEntry) * (entryCount + 1) + classPathLength, J9MEM_CATEGORY_CLASSES);
Expand Down Expand Up @@ -253,7 +253,7 @@ addJarToSystemClassLoaderClassPathEntries(J9JavaVM *vm, const char *filename)
newCount = entryCount + 1;
classLoader->classPathEntries = newEntries;
classLoader->classPathEntryCount = newCount;
if (IS_COLD_RUN(vm)) {
if (IS_RAM_CACHE_ON(vm)) {
imem_free_memory(oldEntries);
} else {
j9mem_free_memory(oldEntries);
Expand All @@ -264,7 +264,7 @@ addJarToSystemClassLoaderClassPathEntries(J9JavaVM *vm, const char *filename)
done:
/* If any error occurred, discard any allocated memory and throw OutOfMemoryError */
if (0 == newCount) {
if (IS_COLD_RUN(vm)) {
if (IS_RAM_CACHE_ON(vm)) {
imem_free_memory(oldEntries);
} else {
j9mem_free_memory(oldEntries);
Expand Down
Loading

0 comments on commit 0638fa2

Please sign in to comment.