hotspot/src/os/windows/vm/hpi_windows.cpp
changeset 1 489c9b5090e2
child 5547 f4b087cbb361
equal deleted inserted replaced
0:fd16c54261b3 1:489c9b5090e2
       
     1 /*
       
     2  * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    20  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    21  * have any questions.
       
    22  *
       
    23  */
       
    24 
       
    25 # include "incls/_precompiled.incl"
       
    26 # include "incls/_hpi_windows.cpp.incl"
       
    27 
       
    28 typedef jint (JNICALL *init_t)(GetInterfaceFunc *, void *);
       
    29 
       
    30 void hpi::initialize_get_interface(vm_calls_t *callbacks)
       
    31 {
       
    32   // Build name of HPI.
       
    33   char lib_name[JVM_MAXPATHLEN];
       
    34 
       
    35   if (HPILibPath && HPILibPath[0]) {
       
    36     strncpy(lib_name, HPILibPath, JVM_MAXPATHLEN - 1);
       
    37     lib_name[JVM_MAXPATHLEN - 1] = '\0';
       
    38   } else {
       
    39     os::jvm_path(lib_name, sizeof lib_name);
       
    40 
       
    41 #ifdef PRODUCT
       
    42     const char *hpi_lib = "\\hpi.dll";
       
    43 #else
       
    44     char *ptr = strrchr(lib_name, '\\');
       
    45     //  On Win98 GetModuleFileName() returns the path in the upper case.
       
    46     assert(_strnicmp(ptr, "\\jvm",4) == 0, "invalid library name");
       
    47     const char *hpi_lib = (_strnicmp(ptr, "\\jvm_g",6) == 0) ? "\\hpi_g.dll" : "\\hpi.dll";
       
    48 #endif
       
    49 
       
    50     *(::strrchr(lib_name, '\\')) = '\0';  /* get rid of "\\jvm.dll" */
       
    51     char *p = ::strrchr(lib_name, '\\');
       
    52     if (p != NULL) *p = '\0';             /* get rid of "\\hotspot" */
       
    53     strcat(lib_name, hpi_lib);
       
    54   }
       
    55 
       
    56   // Load it.
       
    57   if (TraceHPI) tty->print_cr("Loading HPI %s ", lib_name);
       
    58   HINSTANCE lib_handle = LoadLibrary(lib_name);
       
    59   if (lib_handle == NULL) {
       
    60     if (TraceHPI) tty->print_cr("LoadLibrary failed, code = %d", GetLastError());
       
    61     return;
       
    62   }
       
    63 
       
    64   // Find hpi initializer.
       
    65   init_t initer = (init_t)GetProcAddress(lib_handle, "DLL_Initialize");
       
    66   if (initer == NULL) {
       
    67     if (TraceHPI) tty->print_cr("GetProcAddress failed, errcode = %d", GetLastError());
       
    68     return;
       
    69   }
       
    70 
       
    71   // Call initializer.
       
    72   jint init_result = (*initer)(&_get_interface, callbacks);
       
    73   if (init_result < 0) {
       
    74     if (TraceHPI) tty->print_cr("DLL_Initialize failed, returned %ld", init_result);
       
    75     return;
       
    76   }
       
    77 
       
    78   if (TraceHPI) tty->print_cr("success");
       
    79   return;
       
    80 }