31 #include <stdarg.h> 32 #include <string.h> 33 #include <sys/types.h> 34 #include <sys/stat.h> 35 #include <wtypes.h> 36 #include <commctrl.h> 37 38 #include <jni.h> 39 #include "java.h" 40 41 #define JVM_DLL "jvm.dll" 42 #define JAVA_DLL "java.dll" 43 44 /* 45 * Prototypes. 46 */ 47 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype, 48 char *jvmpath, jint jvmpathsize); 49 static jboolean GetJREPath(char *path, jint pathsize); 50 51 /* We supports warmup for UI stack that is performed in parallel 52 * to VM initialization. 53 * This helps to improve startup of UI application as warmup phase 54 * might be long due to initialization of OS or hardware resources. 55 * It is not CPU bound and therefore it does not interfere with VM init. 56 * Obviously such warmup only has sense for UI apps and therefore it needs 57 * to be explicitly requested by passing -Dsun.awt.warmup=true property 58 * (this is always the case for plugin/javaws). 59 * 60 * Implementation launches new thread after VM starts and use it to perform 61 * warmup code (platform dependent). 62 * This thread is later reused as AWT toolkit thread as graphics toolkit 63 * often assume that they are used from the same thread they were launched on. 64 * 65 * At the moment we only support warmup for D3D. It only possible on windows 66 * and only if other flags do not prohibit this (e.g. OpenGL support requested). 67 */ 68 #undef ENABLE_AWT_PRELOAD 69 #ifndef JAVA_ARGS /* turn off AWT preloading for javac, jar, etc */ 70 /* CR6999872: fastdebug crashes if awt library is loaded before JVM is 329 return JNI_FALSE; 330 } 331 /* Does this app ship a private JRE in <apphome>\jre directory? */ 332 JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path); 333 if (stat(javadll, &s) == 0) { 334 JLI_StrCat(path, "\\jre"); 335 JLI_TraceLauncher("JRE path is %s\n", path); 336 return JNI_TRUE; 337 } 338 } 339 340 /* Try getting path to JRE from path to JLI.DLL */ 341 if (GetApplicationHomeFromDll(path, pathsize)) { 342 JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path); 343 if (stat(javadll, &s) == 0) { 344 JLI_TraceLauncher("JRE path is %s\n", path); 345 return JNI_TRUE; 346 } 347 } 348 349 JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); 350 return JNI_FALSE; 351 } 352 353 /* 354 * Given a JRE location and a JVM type, construct what the name the 355 * JVM shared library will be. Return true, if such a library 356 * exists, false otherwise. 357 */ 358 static jboolean 359 GetJVMPath(const char *jrepath, const char *jvmtype, 360 char *jvmpath, jint jvmpathsize) 361 { 362 struct stat s; 363 if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) { 364 JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype); 365 } else { 366 JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL, 367 jrepath, jvmtype); 368 } | 31 #include <stdarg.h> 32 #include <string.h> 33 #include <sys/types.h> 34 #include <sys/stat.h> 35 #include <wtypes.h> 36 #include <commctrl.h> 37 38 #include <jni.h> 39 #include "java.h" 40 41 #define JVM_DLL "jvm.dll" 42 #define JAVA_DLL "java.dll" 43 44 /* 45 * Prototypes. 46 */ 47 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype, 48 char *jvmpath, jint jvmpathsize); 49 static jboolean GetJREPath(char *path, jint pathsize); 50 51 #ifdef USE_REGISTRY_LOOKUP 52 jboolean GetPublicJREHome(char *buf, jint bufsize); 53 #endif 54 55 /* We supports warmup for UI stack that is performed in parallel 56 * to VM initialization. 57 * This helps to improve startup of UI application as warmup phase 58 * might be long due to initialization of OS or hardware resources. 59 * It is not CPU bound and therefore it does not interfere with VM init. 60 * Obviously such warmup only has sense for UI apps and therefore it needs 61 * to be explicitly requested by passing -Dsun.awt.warmup=true property 62 * (this is always the case for plugin/javaws). 63 * 64 * Implementation launches new thread after VM starts and use it to perform 65 * warmup code (platform dependent). 66 * This thread is later reused as AWT toolkit thread as graphics toolkit 67 * often assume that they are used from the same thread they were launched on. 68 * 69 * At the moment we only support warmup for D3D. It only possible on windows 70 * and only if other flags do not prohibit this (e.g. OpenGL support requested). 71 */ 72 #undef ENABLE_AWT_PRELOAD 73 #ifndef JAVA_ARGS /* turn off AWT preloading for javac, jar, etc */ 74 /* CR6999872: fastdebug crashes if awt library is loaded before JVM is 333 return JNI_FALSE; 334 } 335 /* Does this app ship a private JRE in <apphome>\jre directory? */ 336 JLI_Snprintf(javadll, sizeof (javadll), "%s\\jre\\bin\\" JAVA_DLL, path); 337 if (stat(javadll, &s) == 0) { 338 JLI_StrCat(path, "\\jre"); 339 JLI_TraceLauncher("JRE path is %s\n", path); 340 return JNI_TRUE; 341 } 342 } 343 344 /* Try getting path to JRE from path to JLI.DLL */ 345 if (GetApplicationHomeFromDll(path, pathsize)) { 346 JLI_Snprintf(javadll, sizeof(javadll), "%s\\bin\\" JAVA_DLL, path); 347 if (stat(javadll, &s) == 0) { 348 JLI_TraceLauncher("JRE path is %s\n", path); 349 return JNI_TRUE; 350 } 351 } 352 353 #ifdef USE_REGISTRY_LOOKUP 354 /* Lookup public JRE using Windows registry. */ 355 if (GetPublicJREHome(path, pathsize)) { 356 JLI_TraceLauncher("JRE path is %s\n", path); 357 return JNI_TRUE; 358 } 359 #endif 360 361 JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL); 362 return JNI_FALSE; 363 } 364 365 /* 366 * Given a JRE location and a JVM type, construct what the name the 367 * JVM shared library will be. Return true, if such a library 368 * exists, false otherwise. 369 */ 370 static jboolean 371 GetJVMPath(const char *jrepath, const char *jvmtype, 372 char *jvmpath, jint jvmpathsize) 373 { 374 struct stat s; 375 if (JLI_StrChr(jvmtype, '/') || JLI_StrChr(jvmtype, '\\')) { 376 JLI_Snprintf(jvmpath, jvmpathsize, "%s\\" JVM_DLL, jvmtype); 377 } else { 378 JLI_Snprintf(jvmpath, jvmpathsize, "%s\\bin\\%s\\" JVM_DLL, 379 jrepath, jvmtype); 380 } |