jdk/src/windows/bin/java_md.c
changeset 7004 3f92ea1ffcac
parent 6535 77ffd0e75bfb
child 7048 90f459535526
equal deleted inserted replaced
7003:7d8d9506b4ee 7004:3f92ea1ffcac
    49 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
    49 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
    50                            char *jvmpath, jint jvmpathsize);
    50                            char *jvmpath, jint jvmpathsize);
    51 static jboolean GetJREPath(char *path, jint pathsize);
    51 static jboolean GetJREPath(char *path, jint pathsize);
    52 static void EnsureJreInstallation(const char *jrepath);
    52 static void EnsureJreInstallation(const char *jrepath);
    53 
    53 
       
    54 /* We supports warmup for UI stack that is performed in parallel
       
    55  * to VM initialization.
       
    56  * This helps to improve startup of UI application as warmup phase
       
    57  * might be long due to initialization of OS or hardware resources.
       
    58  * It is not CPU bound and therefore it does not interfere with VM init.
       
    59  * Obviously such warmup only has sense for UI apps and therefore it needs
       
    60  * to be explicitly requested by passing -Dsun.awt.warmup=true property
       
    61  * (this is always the case for plugin/javaws).
       
    62  *
       
    63  * Implementation launches new thread after VM starts and use it to perform
       
    64  * warmup code (platform dependent).
       
    65  * This thread is later reused as AWT toolkit thread as graphics toolkit
       
    66  * often assume that they are used from the same thread they were launched on.
       
    67  *
       
    68  * At the moment we only support warmup for D3D. It only possible on windows
       
    69  * and only if other flags do not prohibit this (e.g. OpenGL support requested).
       
    70  */
       
    71 #undef ENABLE_AWT_PRELOAD
       
    72 #ifndef JAVA_ARGS /* turn off AWT preloading for javac, jar, etc */
       
    73     #define ENABLE_AWT_PRELOAD
       
    74 #endif
       
    75 
       
    76 #ifdef ENABLE_AWT_PRELOAD
       
    77 /* "AWT was preloaded" flag;
       
    78  * turned on by AWTPreload().
       
    79  */
       
    80 int awtPreloaded = 0;
       
    81 
       
    82 /* Calls a function with the name specified
       
    83  * the function must be int(*fn)(void).
       
    84  */
       
    85 int AWTPreload(const char *funcName);
       
    86 /* stops AWT preloading */
       
    87 void AWTPreloadStop();
       
    88 
       
    89 /* D3D preloading */
       
    90 /* -1: not initialized; 0: OFF, 1: ON */
       
    91 int awtPreloadD3D = -1;
       
    92 /* command line parameter to swith D3D preloading on */
       
    93 #define PARAM_PRELOAD_D3D "-Dsun.awt.warmup"
       
    94 /* D3D/OpenGL management parameters */
       
    95 #define PARAM_NODDRAW "-Dsun.java2d.noddraw"
       
    96 #define PARAM_D3D "-Dsun.java2d.d3d"
       
    97 #define PARAM_OPENGL "-Dsun.java2d.opengl"
       
    98 /* funtion in awt.dll (src/windows/native/sun/java2d/d3d/D3DPipelineManager.cpp) */
       
    99 #define D3D_PRELOAD_FUNC "preloadD3D"
       
   100 
       
   101 
       
   102 /* Extracts value of a parameter with the specified name
       
   103  * from command line argument (returns pointer in the argument).
       
   104  * Returns NULL if the argument does not contains the parameter.
       
   105  * e.g.:
       
   106  * GetParamValue("theParam", "theParam=value") returns pointer to "value".
       
   107  */
       
   108 const char * GetParamValue(const char *paramName, const char *arg) {
       
   109     int nameLen = JLI_StrLen(paramName);
       
   110     if (JLI_StrNCmp(paramName, arg, nameLen) == 0) {
       
   111         /* arg[nameLen] is valid (may contain final NULL) */
       
   112         if (arg[nameLen] == '=') {
       
   113             return arg + nameLen + 1;
       
   114         }
       
   115     }
       
   116     return NULL;
       
   117 }
       
   118 
       
   119 /* Checks if commandline argument contains property specified
       
   120  * and analyze it as boolean property (true/false).
       
   121  * Returns -1 if the argument does not contain the parameter;
       
   122  * Returns 1 if the argument contains the parameter and its value is "true";
       
   123  * Returns 0 if the argument contains the parameter and its value is "false".
       
   124  */
       
   125 int GetBoolParamValue(const char *paramName, const char *arg) {
       
   126     const char * paramValue = GetParamValue(paramName, arg);
       
   127     if (paramValue != NULL) {
       
   128         if (JLI_StrCaseCmp(paramValue, "true") == 0) {
       
   129             return 1;
       
   130         }
       
   131         if (JLI_StrCaseCmp(paramValue, "false") == 0) {
       
   132             return 0;
       
   133         }
       
   134     }
       
   135     return -1;
       
   136 }
       
   137 #endif /* ENABLE_AWT_PRELOAD */
       
   138 
       
   139 
    54 static jboolean _isjavaw = JNI_FALSE;
   140 static jboolean _isjavaw = JNI_FALSE;
    55 
   141 
    56 
   142 
    57 jboolean
   143 jboolean
    58 IsJavaw()
   144 IsJavaw()
   130     if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
   216     if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
   131         JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
   217         JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
   132         exit(4);
   218         exit(4);
   133     }
   219     }
   134     /* If we got here, jvmpath has been correctly initialized. */
   220     /* If we got here, jvmpath has been correctly initialized. */
       
   221 
       
   222     /* Check if we need preload AWT */
       
   223 #ifdef ENABLE_AWT_PRELOAD
       
   224     argv = *pargv;
       
   225     for (i = 0; i < *pargc ; i++) {
       
   226         /* Tests the "turn on" parameter only if not set yet. */
       
   227         if (awtPreloadD3D < 0) {
       
   228             if (GetBoolParamValue(PARAM_PRELOAD_D3D, argv[i]) == 1) {
       
   229                 awtPreloadD3D = 1;
       
   230             }
       
   231         }
       
   232         /* Test parameters which can disable preloading if not already disabled. */
       
   233         if (awtPreloadD3D != 0) {
       
   234             if (GetBoolParamValue(PARAM_NODDRAW, argv[i]) == 1
       
   235                 || GetBoolParamValue(PARAM_D3D, argv[i]) == 0
       
   236                 || GetBoolParamValue(PARAM_OPENGL, argv[i]) == 1)
       
   237             {
       
   238                 awtPreloadD3D = 0;
       
   239                 /* no need to test the rest of the parameters */
       
   240                 break;
       
   241             }
       
   242         }
       
   243     }
       
   244 #endif /* ENABLE_AWT_PRELOAD */
   135 }
   245 }
   136 
   246 
   137 
   247 
   138 static jboolean
   248 static jboolean
   139 LoadMSVCRT()
   249 LoadMSVCRT()
  1085                              continuation,
  1195                              continuation,
  1086                              args,
  1196                              args,
  1087                              0,
  1197                              0,
  1088                              &thread_id);
  1198                              &thread_id);
  1089     }
  1199     }
       
  1200 
       
  1201     /* AWT preloading (AFTER main thread start) */
       
  1202 #ifdef ENABLE_AWT_PRELOAD
       
  1203     /* D3D preloading */
       
  1204     if (awtPreloadD3D != 0) {
       
  1205         char *envValue;
       
  1206         /* D3D routines checks env.var J2D_D3D if no appropriate
       
  1207          * command line params was specified
       
  1208          */
       
  1209         envValue = getenv("J2D_D3D");
       
  1210         if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
       
  1211             awtPreloadD3D = 0;
       
  1212         }
       
  1213         /* Test that AWT preloading isn't disabled by J2D_D3D_PRELOAD env.var */
       
  1214         envValue = getenv("J2D_D3D_PRELOAD");
       
  1215         if (envValue != NULL && JLI_StrCaseCmp(envValue, "false") == 0) {
       
  1216             awtPreloadD3D = 0;
       
  1217         }
       
  1218         if (awtPreloadD3D < 0) {
       
  1219             /* If awtPreloadD3D is still undefined (-1), test
       
  1220              * if it is turned on by J2D_D3D_PRELOAD env.var.
       
  1221              * By default it's turned OFF.
       
  1222              */
       
  1223             awtPreloadD3D = 0;
       
  1224             if (envValue != NULL && JLI_StrCaseCmp(envValue, "true") == 0) {
       
  1225                 awtPreloadD3D = 1;
       
  1226             }
       
  1227          }
       
  1228     }
       
  1229     if (awtPreloadD3D) {
       
  1230         AWTPreload(D3D_PRELOAD_FUNC);
       
  1231     }
       
  1232 #endif /* ENABLE_AWT_PRELOAD */
       
  1233 
  1090     if (thread_handle) {
  1234     if (thread_handle) {
  1091       WaitForSingleObject(thread_handle, INFINITE);
  1235       WaitForSingleObject(thread_handle, INFINITE);
  1092       GetExitCodeThread(thread_handle, &rslt);
  1236       GetExitCodeThread(thread_handle, &rslt);
  1093       CloseHandle(thread_handle);
  1237       CloseHandle(thread_handle);
  1094     } else {
  1238     } else {
  1095       rslt = continuation(args);
  1239       rslt = continuation(args);
  1096     }
  1240     }
       
  1241 
       
  1242 #ifdef ENABLE_AWT_PRELOAD
       
  1243     if (awtPreloaded) {
       
  1244         AWTPreloadStop();
       
  1245     }
       
  1246 #endif /* ENABLE_AWT_PRELOAD */
       
  1247 
  1097     return rslt;
  1248     return rslt;
  1098 }
  1249 }
  1099 
  1250 
  1100 /* Unix only, empty on windows. */
  1251 /* Unix only, empty on windows. */
  1101 void SetJavaLauncherPlatformProps() {}
  1252 void SetJavaLauncherPlatformProps() {}
  1138     icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  1289     icx.dwSize = sizeof(INITCOMMONCONTROLSEX);
  1139     InitCommonControlsEx(&icx);
  1290     InitCommonControlsEx(&icx);
  1140     _isjavaw = javaw;
  1291     _isjavaw = javaw;
  1141     JLI_SetTraceLauncher();
  1292     JLI_SetTraceLauncher();
  1142 }
  1293 }
       
  1294 
       
  1295 
       
  1296 /* ============================== */
       
  1297 /* AWT preloading */
       
  1298 #ifdef ENABLE_AWT_PRELOAD
       
  1299 
       
  1300 typedef int FnPreloadStart(void);
       
  1301 typedef void FnPreloadStop(void);
       
  1302 static FnPreloadStop *fnPreloadStop = NULL;
       
  1303 static HMODULE hPreloadAwt = NULL;
       
  1304 
       
  1305 /*
       
  1306  * Starts AWT preloading
       
  1307  */
       
  1308 int AWTPreload(const char *funcName)
       
  1309 {
       
  1310     int result = -1;
       
  1311     /* load AWT library once (if several preload function should be called) */
       
  1312     if (hPreloadAwt == NULL) {
       
  1313         /* awt.dll is not loaded yet */
       
  1314         char libraryPath[MAXPATHLEN];
       
  1315         int jrePathLen = 0;
       
  1316         HMODULE hJava = NULL;
       
  1317         HMODULE hVerify = NULL;
       
  1318 
       
  1319         while (1) {
       
  1320             /* awt.dll depends on jvm.dll & java.dll;
       
  1321              * jvm.dll is already loaded, so we need only java.dll;
       
  1322              * java.dll depends on MSVCRT lib & verify.dll.
       
  1323              */
       
  1324             if (!GetJREPath(libraryPath, MAXPATHLEN)) {
       
  1325                 break;
       
  1326             }
       
  1327 
       
  1328             /* save path length */
       
  1329             jrePathLen = JLI_StrLen(libraryPath);
       
  1330 
       
  1331             /* load msvcrt 1st */
       
  1332             LoadMSVCRT();
       
  1333 
       
  1334             /* load verify.dll */
       
  1335             JLI_StrCat(libraryPath, "\\bin\\verify.dll");
       
  1336             hVerify = LoadLibrary(libraryPath);
       
  1337             if (hVerify == NULL) {
       
  1338                 break;
       
  1339             }
       
  1340 
       
  1341             /* restore jrePath */
       
  1342             libraryPath[jrePathLen] = 0;
       
  1343             /* load java.dll */
       
  1344             JLI_StrCat(libraryPath, "\\bin\\" JAVA_DLL);
       
  1345             hJava = LoadLibrary(libraryPath);
       
  1346             if (hJava == NULL) {
       
  1347                 break;
       
  1348             }
       
  1349 
       
  1350             /* restore jrePath */
       
  1351             libraryPath[jrePathLen] = 0;
       
  1352             /* load awt.dll */
       
  1353             JLI_StrCat(libraryPath, "\\bin\\awt.dll");
       
  1354             hPreloadAwt = LoadLibrary(libraryPath);
       
  1355             if (hPreloadAwt == NULL) {
       
  1356                 break;
       
  1357             }
       
  1358 
       
  1359             /* get "preloadStop" func ptr */
       
  1360             fnPreloadStop = (FnPreloadStop *)GetProcAddress(hPreloadAwt, "preloadStop");
       
  1361 
       
  1362             break;
       
  1363         }
       
  1364     }
       
  1365 
       
  1366     if (hPreloadAwt != NULL) {
       
  1367         FnPreloadStart *fnInit = (FnPreloadStart *)GetProcAddress(hPreloadAwt, funcName);
       
  1368         if (fnInit != NULL) {
       
  1369             /* don't forget to stop preloading */
       
  1370             awtPreloaded = 1;
       
  1371 
       
  1372             result = fnInit();
       
  1373         }
       
  1374     }
       
  1375 
       
  1376     return result;
       
  1377 }
       
  1378 
       
  1379 /*
       
  1380  * Terminates AWT preloading
       
  1381  */
       
  1382 void AWTPreloadStop() {
       
  1383     if (fnPreloadStop != NULL) {
       
  1384         fnPreloadStop();
       
  1385     }
       
  1386 }
       
  1387 
       
  1388 #endif /* ENABLE_AWT_PRELOAD */