int java_init(euca_opts *args, java_home_t *data) { jint (*hotspot_main)(JavaVM **, JNIEnv **, JavaVMInitArgs *); char *libjvm_path = NULL; if ((libjvm_path = java_library(args, data)) == NULL) __fail("Cannot locate JVM library file"); dso_handle libjvm_handle = NULL; __die( (libjvm_handle = dlopen(libjvm_path, RTLD_GLOBAL | RTLD_NOW)) == NULL, "Cannot dynamically link to %s\n%s", libjvm_path, dso_error()); __debug("JVM library %s loaded", libjvm_path); if ((hotspot_main = dlsym(libjvm_handle, "JNI_CreateJavaVM")) == NULL) __fail("Cannot find JVM library entry point"); JavaVMInitArgs arg; arg.ignoreUnrecognized = 0; #if defined(JNI_VERSION_1_4) arg.version=JNI_VERSION_1_4; #else arg.version = JNI_VERSION_1_2; #endif JavaVMOption *opt = NULL; char* java_class_path = java_library_path(args); __debug("Using classpath:\n%s", java_class_path); #define JVM_MAX_OPTS 128 int x = -1, i = 0; opt = (JavaVMOption *) malloc(JVM_MAX_OPTS * sizeof(JavaVMOption)); for (i = 0; i < JVM_MAX_OPTS; i++) opt[i].extraInfo = NULL; i = -1; while (jvm_default_opts[++i] != NULL) JVM_ARG(opt[++x], jvm_default_opts[i], GETARG(args, home)); if (args->exhaustive_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); } else { int exhaust = 0; if (args->exhaustive_db_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=FATAL"); } if (args->exhaustive_cc_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=FATAL"); } if (args->exhaustive_user_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=FATAL"); } if (args->exhaustive_external_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=FATAL"); } if (exhaust) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=FATAL"); } } JVM_ARG(opt[++x], "-Deuca.version=%1$s", ARGUMENTS_VERSION); JVM_ARG(opt[++x], "-Deuca.log.level=%1$s", GETARG(args, log_level)); JVM_ARG(opt[++x], "-Deuca.log.appender=%1$s", GETARG(args, log_appender)); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) { JVM_ARG(opt[++x], "-Deuca.extra_version=%1$s", GETARG(args, extra_version)); } if (args->initialize_flag) { JVM_ARG(opt[++x], "-Deuca.initialize=true"); JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } else { if (args->remote_dns_flag) { JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } if (args->disable_iscsi_flag) { JVM_ARG(opt[++x], "-Deuca.disable.iscsi=true"); } } if (args->force_remote_bootstrap_flag || args->disable_cloud_flag) { JVM_ARG(opt[++x], "-Deuca.force.remote.bootstrap=true"); } if (args->debug_noha_flag) { JVM_ARG(opt[++x], "-Deuca.noha.cloud"); } if (args->db_home_given) { JVM_ARG(opt[++x], "-Deuca.db.home=%s", GETARG(args, db_home)); } if (args->debug_flag) { JVM_ARG(opt[++x], "-XX:+HeapDumpOnOutOfMemoryError"); JVM_ARG(opt[++x], "-XX:HeapDumpPath=%s/var/log/eucalyptus/", GETARG(args, home)); JVM_ARG(opt[++x], "-Xdebug"); JVM_ARG( opt[++x], "-Xrunjdwp:transport=dt_socket,server=y,suspend=%2$s,address=%1$d", GETARG(args, debug_port), (args->debug_suspend_flag ? "y" : "n")); } if (args->jmx_flag || args->debug_flag) { JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote");//TODO:GRZE:wrapup jmx stuff here. JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.port=8772"); JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.authenticate=false");//TODO:GRZE:RELEASE FIXME to use ssl JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.ssl=false"); } if (args->verbose_flag ) { JVM_ARG(opt[++x], "-verbose:gc"); JVM_ARG(opt[++x], "-XX:+PrintGCTimeStamps"); JVM_ARG(opt[++x], "-XX:+PrintGCDetails"); } if (args->profile_flag && args->agentlib_given) { JVM_ARG(opt[++x], "-agentlib:%s", GETARG(args, agentlib)); } else if (args->profile_flag) { JVM_ARG(opt[++x], "-agentlib:jprofilerti=port=8849"); JVM_ARG(opt[++x], "-Xbootclasspath/a:%1$s/bin/agent.jar", GETARG(args, profiler_home)); } if (args->user_given) { JVM_ARG(opt[++x], "-Deuca.user=%s", GETARG(args, user)); } for (i = 0; i < args->jvm_args_given; i++) JVM_ARG(opt[++x], "-X%s", args->jvm_args_arg[i]); for (i = 0; i < args->define_given; i++) JVM_ARG(opt[++x], "-D%s", args->define_arg[i]); for (i = 0; i < args->bootstrap_host_given; i++) JVM_ARG(opt[++x], "-Deuca.bootstrap.host.%d=%s", i, args->bootstrap_host_arg[i]); for (i = 0; i < args->bind_addr_given; i++) JVM_ARG(opt[++x], "-Deuca.bind.addr.%d=%s", i, args->bind_addr_arg[i]); opt[++x].optionString = java_class_path; opt[x].extraInfo = NULL; opt[++x].optionString = "abort"; opt[x].extraInfo = java_fail; arg.nOptions = x + 1; arg.options = opt; if (debug) { __debug("+-------------------------------------------------------"); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) __debug("| Eucalyptus version: %s-%s", ARGUMENTS_VERSION, GETARG(args, extra_version)); else __debug("| Eucalyptus version: %s", ARGUMENTS_VERSION); __debug("| JNI version: %x", arg.version); __debug("| Ignore Unrecognized Arguments: %d", arg.ignoreUnrecognized); __debug("| Extra options: %d", arg.nOptions); for (x = 0; x < arg.nOptions; x++) __debug("| \"%-80.80s\" (0x%p)", opt[x].optionString, opt[x].extraInfo); __debug("+-------------------------------------------------------"); } __debug("Starting JVM."); jint ret = 0; while ((ret = (*hotspot_main)(&jvm, &env, &arg) == 123)) ; __die(ret < 0, "Failed to create JVM"); java_load_bootstrapper(); dlclose(libjvm_handle); return 1; }
int java_init(euca_opts *args, java_home_t *data) { jint (*hotspot_main)(JavaVM **, JNIEnv **, JavaVMInitArgs *); char *libjvm_path=NULL; if ((libjvm_path=java_library(args,data))==NULL) __fail("Cannot locate JVM library file"); dso_handle libjvm_handle=NULL; __die((libjvm_handle=dlopen(libjvm_path,RTLD_GLOBAL|RTLD_NOW))==NULL,"Cannot dynamically link to %s\n%s",libjvm_path,dso_error()); __debug("JVM library %s loaded",libjvm_path); if ((hotspot_main=dlsym(libjvm_handle,"JNI_CreateJavaVM"))==NULL) __fail("Cannot find JVM library entry point"); JavaVMInitArgs arg; arg.ignoreUnrecognized=0; #if defined(JNI_VERSION_1_4) arg.version=JNI_VERSION_1_4; #else arg.version=JNI_VERSION_1_2; #endif JavaVMOption *opt=NULL; char* java_class_path = java_library_path(args); __debug("Using classpath:\n%s",java_class_path); #define JVM_MAX_OPTS 128 int x = -1, i = 0; opt=(JavaVMOption *)malloc(JVM_MAX_OPTS*sizeof(JavaVMOption)); for(i=0;i<JVM_MAX_OPTS;i++) opt[i].extraInfo=NULL; i = -1; while(jvm_default_opts[++i]!= NULL) JVM_ARG(opt[++x],jvm_default_opts[i],GETARG(args,home)); if(args->exhaustive_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.db=TRACE"); JVM_ARG(opt[++x],"-Deuca.log.exhaustive.user=TRACE"); JVM_ARG(opt[++x],"-Deuca.log.exhaustive.cc=TRACE"); JVM_ARG(opt[++x],"-Deuca.log.exhaustive.external=TRACE"); } else { if(args->exhaustive_db_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.db=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.db=FATAL"); } if(args->exhaustive_cc_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.cc=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.cc=FATAL"); } if(args->exhaustive_user_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.user=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.user=FATAL"); } if(args->exhaustive_external_flag) { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.external=TRACE"); } else { JVM_ARG(opt[++x],"-Deuca.log.exhaustive.external=FATAL"); } } JVM_ARG(opt[++x],"-Deuca.log.level=%1$s",GETARG(args,log_level)); JVM_ARG(opt[++x],"-Deuca.log.appender=%1$s",GETARG(args,log_appender)); JVM_ARG(opt[++x],"-Deuca.db.port=%1$d",9001);//TODO: add cli parameter JVM_ARG(opt[++x],"-Deuca.db.host=%1$s",GETARG(args,cloud_host)); JVM_ARG(opt[++x],"-Deuca.walrus.host=%1$s",GETARG(args,walrus_host)); if(args->disable_dns_flag) { JVM_ARG(opt[++x],"-Deuca.disable.dns=true"); } if(args->disable_storage_flag) { JVM_ARG(opt[++x],"-Deuca.disable.storage=true"); } if(args->disable_cloud_flag) { JVM_ARG(opt[++x],"-Deuca.disable.eucalyptus=true"); } if(args->disable_walrus_flag) { JVM_ARG(opt[++x],"-Deuca.disable.walrus=true"); } if(args->remote_dns_flag) { JVM_ARG(opt[++x],"-Deuca.remote.dns=true"); } if(args->remote_storage_flag) { JVM_ARG(opt[++x],"-Deuca.remote.storage=true"); } if(args->remote_cloud_flag) { JVM_ARG(opt[++x],"-Deuca.remote.cloud=true"); } if(args->remote_walrus_flag) { JVM_ARG(opt[++x],"-Deuca.remote.walrus=true"); } if(args->disable_iscsi_flag) { JVM_ARG(opt[++x],"-Deuca.disable.iscsi=true"); } if(args->debug_flag) { JVM_ARG(opt[++x],"-Xdebug"); JVM_ARG(opt[++x],"-Xrunjdwp:transport=dt_socket,server=y,suspend=%2$s,address=%1$d",GETARG(args,debug_port),(args->debug_suspend_flag?"y":"n")); } if(args->debug_flag||args->profile_flag) { JVM_ARG(opt[++x],"-Dcom.sun.management.jmxremote"); JVM_ARG(opt[++x],"-XX:+HeapDumpOnOutOfMemoryError"); JVM_ARG(opt[++x],"-XX:HeapDumpPath=%s/var/log/eucalyptus/",GETARG(args,home)); } if(args->profile_flag && args->agentlib_given ) { JVM_ARG(opt[++x],"-agentlib:%s",GETARG(args,agentlib)); } else if(args->profile_flag) { JVM_ARG(opt[++x],"-agentlib:jprofilerti=port=8849"); JVM_ARG(opt[++x],"-Xbootclasspath/a:%1$s/bin/agent.jar",GETARG(args,profiler_home)); } for (i=0; i<args->jvm_args_given; i++) JVM_ARG(opt[++x],"-X%s",args->jvm_args_arg[i]); for (i=0; i<args->define_given; i++) JVM_ARG(opt[++x],"-D%s",args->define_arg[i]); opt[++x].optionString=java_class_path; opt[x].extraInfo=NULL; opt[++x].optionString="abort"; opt[x].extraInfo=java_fail; arg.nOptions = x+1; arg.options=opt; if (debug) { __debug("+-------------------------------------------------------"); __debug("| Version: %x", arg.version); __debug("| Ignore Unrecognized Arguments: %d", arg.ignoreUnrecognized); __debug("| Extra options: %d", arg.nOptions); for (x=0; x<arg.nOptions; x++) __debug("| \"%-80.80s\" (0x%p)",opt[x].optionString, opt[x].extraInfo); __debug("+-------------------------------------------------------"); } __debug("Starting JVM."); jint ret = 0; while((ret=(*hotspot_main)(&jvm, &env, &arg)==123)); __die(ret<0,"Failed to create JVM"); java_load_bootstrapper(); return 1; }
int java_init(euca_opts * args, java_home_t * data) { jint(*hotspot_main) (JavaVM **, JNIEnv **, JavaVMInitArgs *); char *libjvm_path = NULL; if ((libjvm_path = java_library(args, data)) == NULL) __fail("Cannot locate JVM library file"); dso_handle libjvm_handle = NULL; __die((libjvm_handle = dlopen(libjvm_path, RTLD_GLOBAL | RTLD_NOW)) == NULL, "Cannot dynamically link to %s\n%s", libjvm_path, dso_error()); __debug("JVM library %s loaded", libjvm_path); if ((hotspot_main = dlsym(libjvm_handle, "JNI_CreateJavaVM")) == NULL) __fail("Cannot find JVM library entry point"); JavaVMInitArgs arg; arg.ignoreUnrecognized = 0; #if defined(JNI_VERSION_1_4) arg.version = JNI_VERSION_1_4; #else arg.version = JNI_VERSION_1_2; #endif JavaVMOption *opt = NULL; char *java_class_path = java_library_path(args); __debug("Using classpath:\n%s", java_class_path); #define JVM_MAX_OPTS 128 int x = -1, i = 0, encoding_not_defined_flag = 1; opt = (JavaVMOption *) malloc(JVM_MAX_OPTS * sizeof(JavaVMOption)); for (i = 0; i < JVM_MAX_OPTS; i++) opt[i].extraInfo = NULL; i = -1; while (jvm_default_opts[++i] != NULL) JVM_ARG(opt[++x], jvm_default_opts[i], GETARG(args, home)); // setting heap size to half of total memory if it was not set by user char *s, str[16], size_i; long size; str[0] = 0; for (i = 0; i < args->jvm_args_given; i++) { if ((s = strstr(args->jvm_args_arg[i], "mx")) && sscanf(s, "mx%s", str) == 1) { break; } } if (str[0] != 0) { sscanf (str,"%ld%c", &size, &size_i); switch(size_i) { case 'k' : case 'K' : size = size * 1024L; break; case 'm' : case 'M' : size = size * 1024L * 1024L; break; case 'g' : case 'G' : size = size * GIG; break; default: size = size * 1L; } __debug("User defined heap size is %ld bytes", size); if (size < GIG) { __error("User defined heap size of %ld bytes is set too low and system might now work properly", size); } } else { size_t total_memory = getMemoryTotalSize(); double heap_size_gb = 2; if (total_memory <= 32 * GIG && total_memory >= 4 * GIG) heap_size_gb = ceil(total_memory/GIG/2.0); else if (total_memory > 32 * GIG) heap_size_gb = 16.0; __info("User did not set heap size. Setting it automatically to %.0lfGB base on total memory of %zu bytes", heap_size_gb, total_memory); JVM_ARG(opt[++x], "-Xms%.0lfg", heap_size_gb); JVM_ARG(opt[++x], "-Xmx%.0lfg", heap_size_gb); } if (args->exhaustive_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); } else { int exhaust = 0; if (args->exhaustive_db_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.db=FATAL"); } if (args->exhaustive_cc_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.cc=FATAL"); } if (args->exhaustive_user_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.user=FATAL"); } if (args->exhaustive_external_flag) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=TRACE"); exhaust++; } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive.external=FATAL"); } if (exhaust) { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=TRACE"); } else { JVM_ARG(opt[++x], "-Deuca.log.exhaustive=FATAL"); } } JVM_ARG(opt[++x], "-Deuca.version=%1$s", ARGUMENTS_VERSION); JVM_ARG(opt[++x], "-Deuca.log.level=%1$s", GETARG(args, log_level)); JVM_ARG(opt[++x], "-Deuca.log.appender=%1$s", GETARG(args, log_appender)); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) { JVM_ARG(opt[++x], "-Deuca.extra_version=%1$s", GETARG(args, extra_version)); } if (args->initialize_flag) { JVM_ARG(opt[++x], "-Deuca.initialize=true"); JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } else if (args->upgrade_flag) { JVM_ARG(opt[++x], "-Deuca.upgrade=true"); if (args->upgrade_force_flag) { JVM_ARG(opt[++x], "-Deuca.upgrade.force=true"); } JVM_ARG(opt[++x], "-Deuca.upgrade.old.dir=%1$s", GETARG(args, upgrade_old_dir)); JVM_ARG(opt[++x], "-Deuca.upgrade.old.version=%1$s", GETARG(args, upgrade_old_version)); } else { if (args->remote_dns_flag) { JVM_ARG(opt[++x], "-Deuca.remote.dns=true"); } if (args->disable_iscsi_flag) { JVM_ARG(opt[++x], "-Deuca.disable.iscsi=true"); } } if (args->force_remote_bootstrap_flag || args->disable_cloud_flag) { JVM_ARG(opt[++x], "-Deuca.force.remote.bootstrap=true"); } if (args->debug_noha_flag) { JVM_ARG(opt[++x], "-Deuca.noha.cloud"); } if (args->db_home_given) { JVM_ARG(opt[++x], "-Deuca.db.home=%s", GETARG(args, db_home)); } JVM_ARG(opt[++x], "-XX:+HeapDumpOnOutOfMemoryError"); JVM_ARG(opt[++x], "-XX:HeapDumpPath=%s/var/log/eucalyptus/", GETARG(args, home)); if (args->debug_flag) { JVM_ARG(opt[++x], "-agentlib:jdwp=transport=dt_socket,server=y,suspend=%2$s,address=%1$d", GETARG(args, debug_port), (args->debug_suspend_flag ? "y" : "n")); } if (args->jmx_flag) { JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote"); //TODO:GRZE:wrapup jmx stuff here. JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.port=8772"); JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.authenticate=false"); //TODO:GRZE:RELEASE FIXME to use ssl JVM_ARG(opt[++x], "-Dcom.sun.management.jmxremote.ssl=false"); } if (args->verbose_flag) { JVM_ARG(opt[++x], "-verbose:gc"); JVM_ARG(opt[++x], "-XX:+PrintGCTimeStamps"); JVM_ARG(opt[++x], "-XX:+PrintGCDetails"); } if (args->profile_flag && args->agentlib_given) { JVM_ARG(opt[++x], "-agentlib:%s", GETARG(args, agentlib)); } else if (args->profile_flag) { JVM_ARG(opt[++x], "-agentlib:jprofilerti=port=8849"); JVM_ARG(opt[++x], "-Xbootclasspath/a:%1$s/bin/agent.jar", GETARG(args, profiler_home)); } if (args->user_given) { JVM_ARG(opt[++x], "-Deuca.user=%s", GETARG(args, user)); } for (i = 0; i < args->jvm_args_given; i++) JVM_ARG(opt[++x], "-X%s", args->jvm_args_arg[i]); for (i = 0; i < args->define_given; i++) { JVM_ARG(opt[++x], "-D%s", args->define_arg[i]); if (strncmp(args->define_arg[i], "file.encoding", 13) == 0) encoding_not_defined_flag = 0; } for (i = 0; i < args->bootstrap_host_given; i++) JVM_ARG(opt[++x], "-Deuca.bootstrap.host.%d=%s", i, args->bootstrap_host_arg[i]); for (i = 0; i < args->bind_addr_given; i++) JVM_ARG(opt[++x], "-Deuca.bind.addr.%d=%s", i, args->bind_addr_arg[i]); if (args->mcast_addr_given) { JVM_ARG(opt[++x], "-Deuca.mcast.addr=%s", GETARG(args, mcast_addr)); } if (encoding_not_defined_flag) JVM_ARG(opt[++x], "-Dfile.encoding=UTF-8"); opt[++x].optionString = java_class_path; opt[x].extraInfo = NULL; opt[++x].optionString = "abort"; opt[x].extraInfo = java_fail; arg.nOptions = x + 1; arg.options = opt; if (debug) { __debug("+-------------------------------------------------------"); if (strlen(GETARG(args, extra_version)) > 1 && strncmp(GETARG(args, extra_version), "@", 1)) __debug("| Eucalyptus version: %s-%s", ARGUMENTS_VERSION, GETARG(args, extra_version)); else __debug("| Eucalyptus version: %s", ARGUMENTS_VERSION); __debug("| JNI version: %x", arg.version); __debug("| Ignore Unrecognized Arguments: %d", arg.ignoreUnrecognized); __debug("| Extra options: %d", arg.nOptions); for (x = 0; x < arg.nOptions; x++) __debug("| \"%-80.80s\" (0x%p)", opt[x].optionString, opt[x].extraInfo); __debug("+-------------------------------------------------------"); } __debug("Starting JVM."); jint ret = 0; while ((ret = (*hotspot_main) (&jvm, &env, &arg) == EUCA_RET_RELOAD)) ; __die(ret < 0, "Failed to create JVM"); java_load_bootstrapper(); dlclose(libjvm_handle); return 1; }