src/share/demo/jvmti/hprof/hprof_init.c

Print this page
rev 6641 : [mq]: PrivateTransportTest


1882     addCapabilities(&needed_capabilities);
1883 
1884 }
1885 
1886 /* Dynamic library loading */
1887 static void *
1888 load_library(char *name)
1889 {
1890     char  lname[FILENAME_MAX+1];
1891     char  err_buf[256+FILENAME_MAX+1];
1892     char *boot_path;
1893     void *handle;
1894 
1895     handle = NULL;
1896 
1897     /* The library may be located in different ways, try both, but
1898      *   if it comes from outside the SDK/jre it isn't ours.
1899      */
1900     getSystemProperty("sun.boot.library.path", &boot_path);
1901     md_build_library_name(lname, FILENAME_MAX, boot_path, name);



1902     jvmtiDeallocate(boot_path);
1903     handle = md_load_library(lname, err_buf, (int)sizeof(err_buf));
1904     if ( handle == NULL ) {
1905         /* This may be necessary on Windows. */
1906         md_build_library_name(lname, FILENAME_MAX, "", name);



1907         handle = md_load_library(lname, err_buf, (int)sizeof(err_buf));
1908         if ( handle == NULL ) {
1909             HPROF_ERROR(JNI_TRUE, err_buf);
1910         }
1911     }
1912     return handle;
1913 }
1914 
1915 /* Lookup dynamic function pointer in shared library */
1916 static void *
1917 lookup_library_symbol(void *library, char **symbols, int nsymbols)
1918 {
1919     void *addr;
1920     int   i;
1921 
1922     addr = NULL;
1923     for( i = 0 ; i < nsymbols; i++ ) {
1924         addr = md_find_library_entry(library, symbols[i]);
1925         if ( addr != NULL ) {
1926             break;


1951         return JNI_ERR;
1952     }
1953 
1954     gdata = get_gdata();
1955 
1956     gdata->isLoaded = JNI_TRUE;
1957 
1958     error_setup();
1959 
1960     LOG2("Agent_OnLoad", "gdata setup");
1961 
1962     gdata->jvm = vm;
1963 
1964     /* Get the JVMTI environment */
1965     getJvmti();
1966 
1967 #ifndef SKIP_NPT
1968     getSystemProperty("sun.boot.library.path", &boot_path);
1969     /* Load in NPT library for character conversions */
1970     md_build_library_name(npt_lib, sizeof(npt_lib), boot_path, NPT_LIBNAME);



1971     jvmtiDeallocate(boot_path);
1972     NPT_INITIALIZE(npt_lib, &(gdata->npt), NPT_VERSION, NULL);
1973     if ( gdata->npt == NULL ) {
1974         HPROF_ERROR(JNI_TRUE, "Cannot load npt library");
1975     }
1976     gdata->npt->utf = (gdata->npt->utfInitialize)(NULL);
1977     if ( gdata->npt->utf == NULL ) {
1978         HPROF_ERROR(JNI_TRUE, "Cannot initialize npt utf functions");
1979     }
1980 #endif
1981 
1982     /* Lock needed to protect debug_malloc() code, which is not MT safe */
1983     #ifdef DEBUG
1984         gdata->debug_malloc_lock = createRawMonitor("HPROF debug_malloc lock");
1985     #endif
1986 
1987     parse_options(options);
1988 
1989     LOG2("Agent_OnLoad", "Has jvmtiEnv and options parsed");
1990 




1882     addCapabilities(&needed_capabilities);
1883 
1884 }
1885 
1886 /* Dynamic library loading */
1887 static void *
1888 load_library(char *name)
1889 {
1890     char  lname[FILENAME_MAX+1];
1891     char  err_buf[256+FILENAME_MAX+1];
1892     char *boot_path;
1893     void *handle;
1894 
1895     handle = NULL;
1896 
1897     /* The library may be located in different ways, try both, but
1898      *   if it comes from outside the SDK/jre it isn't ours.
1899      */
1900     getSystemProperty("sun.boot.library.path", &boot_path);
1901     md_build_library_name(lname, FILENAME_MAX, boot_path, name);
1902     if ( strlen(lname) == 0 ) {
1903         HPROF_ERROR(JNI_TRUE, "Could not find library");
1904     }
1905     jvmtiDeallocate(boot_path);
1906     handle = md_load_library(lname, err_buf, (int)sizeof(err_buf));
1907     if ( handle == NULL ) {
1908         /* This may be necessary on Windows. */
1909         md_build_library_name(lname, FILENAME_MAX, "", name);
1910         if ( strlen(lname) == 0 ) {
1911             HPROF_ERROR(JNI_TRUE, "Could not find library");
1912         }
1913         handle = md_load_library(lname, err_buf, (int)sizeof(err_buf));
1914         if ( handle == NULL ) {
1915             HPROF_ERROR(JNI_TRUE, err_buf);
1916         }
1917     }
1918     return handle;
1919 }
1920 
1921 /* Lookup dynamic function pointer in shared library */
1922 static void *
1923 lookup_library_symbol(void *library, char **symbols, int nsymbols)
1924 {
1925     void *addr;
1926     int   i;
1927 
1928     addr = NULL;
1929     for( i = 0 ; i < nsymbols; i++ ) {
1930         addr = md_find_library_entry(library, symbols[i]);
1931         if ( addr != NULL ) {
1932             break;


1957         return JNI_ERR;
1958     }
1959 
1960     gdata = get_gdata();
1961 
1962     gdata->isLoaded = JNI_TRUE;
1963 
1964     error_setup();
1965 
1966     LOG2("Agent_OnLoad", "gdata setup");
1967 
1968     gdata->jvm = vm;
1969 
1970     /* Get the JVMTI environment */
1971     getJvmti();
1972 
1973 #ifndef SKIP_NPT
1974     getSystemProperty("sun.boot.library.path", &boot_path);
1975     /* Load in NPT library for character conversions */
1976     md_build_library_name(npt_lib, sizeof(npt_lib), boot_path, NPT_LIBNAME);
1977     if ( strlen(npt_lib) == 0 ) {
1978         HPROF_ERROR(JNI_TRUE, "Could not find npt library");
1979     }
1980     jvmtiDeallocate(boot_path);
1981     NPT_INITIALIZE(npt_lib, &(gdata->npt), NPT_VERSION, NULL);
1982     if ( gdata->npt == NULL ) {
1983         HPROF_ERROR(JNI_TRUE, "Cannot load npt library");
1984     }
1985     gdata->npt->utf = (gdata->npt->utfInitialize)(NULL);
1986     if ( gdata->npt->utf == NULL ) {
1987         HPROF_ERROR(JNI_TRUE, "Cannot initialize npt utf functions");
1988     }
1989 #endif
1990 
1991     /* Lock needed to protect debug_malloc() code, which is not MT safe */
1992     #ifdef DEBUG
1993         gdata->debug_malloc_lock = createRawMonitor("HPROF debug_malloc lock");
1994     #endif
1995 
1996     parse_options(options);
1997 
1998     LOG2("Agent_OnLoad", "Has jvmtiEnv and options parsed");
1999