src/java.base/windows/native/libjli/java_md.c

Print this page




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <windows.h>
  27 #include <io.h>
  28 #include <process.h>
  29 #include <stdlib.h>
  30 #include <stdio.h>
  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  *


 504         vfprintf(stderr, fmt, vl);
 505         fprintf(stderr, "\n");
 506     }
 507     va_end(vl);
 508 }
 509 
 510 /*
 511  * Just like JLI_ReportErrorMessage, except that it concatenates the system
 512  * error message if any, its upto the calling routine to correctly
 513  * format the separation of the messages.
 514  */
 515 void
 516 JLI_ReportErrorMessageSys(const char *fmt, ...)
 517 {
 518     va_list vl;
 519 
 520     int save_errno = errno;
 521     DWORD       errval;
 522     jboolean freeit = JNI_FALSE;
 523     char  *errtext = NULL;

 524 
 525     va_start(vl, fmt);
 526 
 527     if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
 528         int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
 529             FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
 530             NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
 531         if (errtext == NULL || n == 0) {                /* Paranoia check */
 532             errtext = "";
 533             n = 0;
 534         } else {
 535             freeit = JNI_TRUE;
 536             if (n > 2) {                                /* Drop final CR, LF */
 537                 if (errtext[n - 1] == '\n') n--;
 538                 if (errtext[n - 1] == '\r') n--;
 539                 errtext[n] = '\0';
 540             }
 541         }
 542     } else {   /* C runtime error that has no corresponding DOS error code */
 543         errtext = strerror(save_errno);

 544     }
 545 
 546     if (IsJavaw()) {
 547         char *message;
 548         int mlen;
 549         /* get the length of the string we need */
 550         int len = mlen =  _vscprintf(fmt, vl) + 1;
 551         if (freeit) {
 552            mlen += (int)JLI_StrLen(errtext);
 553         }
 554 
 555         message = (char *)JLI_MemAlloc(mlen);
 556         _vsnprintf(message, len, fmt, vl);
 557         message[len]='\0';
 558 
 559         if (freeit) {
 560            JLI_StrCat(message, errtext);
 561         }
 562 
 563         MessageBox(NULL, message, "Java Virtual Machine Launcher",




  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include <windows.h>
  27 #include <io.h>
  28 #include <process.h>
  29 #include <stdlib.h>
  30 #include <stdio.h>
  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 #include "jdk_strerror.h"
  41 
  42 #define JVM_DLL "jvm.dll"
  43 #define JAVA_DLL "java.dll"
  44 
  45 /*
  46  * Prototypes.
  47  */
  48 static jboolean GetJVMPath(const char *jrepath, const char *jvmtype,
  49                            char *jvmpath, jint jvmpathsize);
  50 static jboolean GetJREPath(char *path, jint pathsize);
  51 
  52 /* We supports warmup for UI stack that is performed in parallel
  53  * to VM initialization.
  54  * This helps to improve startup of UI application as warmup phase
  55  * might be long due to initialization of OS or hardware resources.
  56  * It is not CPU bound and therefore it does not interfere with VM init.
  57  * Obviously such warmup only has sense for UI apps and therefore it needs
  58  * to be explicitly requested by passing -Dsun.awt.warmup=true property
  59  * (this is always the case for plugin/javaws).
  60  *


 505         vfprintf(stderr, fmt, vl);
 506         fprintf(stderr, "\n");
 507     }
 508     va_end(vl);
 509 }
 510 
 511 /*
 512  * Just like JLI_ReportErrorMessage, except that it concatenates the system
 513  * error message if any, its upto the calling routine to correctly
 514  * format the separation of the messages.
 515  */
 516 void
 517 JLI_ReportErrorMessageSys(const char *fmt, ...)
 518 {
 519     va_list vl;
 520 
 521     int save_errno = errno;
 522     DWORD       errval;
 523     jboolean freeit = JNI_FALSE;
 524     char  *errtext = NULL;
 525     char buf[1024];
 526 
 527     va_start(vl, fmt);
 528 
 529     if ((errval = GetLastError()) != 0) {               /* Platform SDK / DOS Error */
 530         int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|
 531             FORMAT_MESSAGE_IGNORE_INSERTS|FORMAT_MESSAGE_ALLOCATE_BUFFER,
 532             NULL, errval, 0, (LPTSTR)&errtext, 0, NULL);
 533         if (errtext == NULL || n == 0) {                /* Paranoia check */
 534             errtext = "";
 535             n = 0;
 536         } else {
 537             freeit = JNI_TRUE;
 538             if (n > 2) {                                /* Drop final CR, LF */
 539                 if (errtext[n - 1] == '\n') n--;
 540                 if (errtext[n - 1] == '\r') n--;
 541                 errtext[n] = '\0';
 542             }
 543         }
 544     } else {   /* C runtime error that has no corresponding DOS error code */
 545         jdk_strerror(save_errno, buf, (size_t) 1024);
 546         errtext = buf;
 547     }
 548 
 549     if (IsJavaw()) {
 550         char *message;
 551         int mlen;
 552         /* get the length of the string we need */
 553         int len = mlen =  _vscprintf(fmt, vl) + 1;
 554         if (freeit) {
 555            mlen += (int)JLI_StrLen(errtext);
 556         }
 557 
 558         message = (char *)JLI_MemAlloc(mlen);
 559         _vsnprintf(message, len, fmt, vl);
 560         message[len]='\0';
 561 
 562         if (freeit) {
 563            JLI_StrCat(message, errtext);
 564         }
 565 
 566         MessageBox(NULL, message, "Java Virtual Machine Launcher",