src/os/aix/vm/loadlib_aix.cpp

Wed, 19 Feb 2014 14:03:09 -0800

author
goetz
date
Wed, 19 Feb 2014 14:03:09 -0800
changeset 6519
941427282eae
parent 0
f90c822e73f8
permissions
-rw-r--r--

8034797: AIX: Fix os::naked_short_sleep() in os_aix.cpp after 8028280
Summary: imlements os::naked_short_sleep(jlong ms) on AIX
Reviewed-by: dholmes, kvn

     1 /*
     2  * Copyright 2012, 2013 SAP AG. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    26 // Implementation of LoadedLibraries and friends
    28 // Ultimately this just uses loadquery()
    29 // See:
    30 // http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp
    31 //      ?topic=/com.ibm.aix.basetechref/doc/basetrf1/loadquery.htm
    33 #ifndef __STDC_FORMAT_MACROS
    34 #define __STDC_FORMAT_MACROS
    35 #endif
    36 // 'allocation.inline.hpp' triggers the inclusion of 'inttypes.h' which defines macros
    37 // required by the definitions in 'globalDefinitions.hpp'. But these macros in 'inttypes.h'
    38 // are only defined if '__STDC_FORMAT_MACROS' is defined!
    39 #include "memory/allocation.inline.hpp"
    40 #include "oops/oop.inline.hpp"
    41 #include "runtime/threadCritical.hpp"
    42 #include "utilities/debug.hpp"
    43 #include "utilities/ostream.hpp"
    44 #include "loadlib_aix.hpp"
    45 #include "porting_aix.hpp"
    47 // For loadquery()
    48 #include <sys/ldr.h>
    50 ///////////////////////////////////////////////////////////////////////////////
    51 // Implementation for LoadedLibraryModule
    53 // output debug info
    54 void LoadedLibraryModule::print(outputStream* os) const {
    55   os->print("%15.15s: text: " INTPTR_FORMAT " - " INTPTR_FORMAT
    56                ", data: " INTPTR_FORMAT " - " INTPTR_FORMAT " ",
    57       shortname, text_from, text_to, data_from, data_to);
    58   os->print(" %s", fullpath);
    59   if (strlen(membername) > 0) {
    60     os->print("(%s)", membername);
    61   }
    62   os->cr();
    63 }
    66 ///////////////////////////////////////////////////////////////////////////////
    67 // Implementation for LoadedLibraries
    69 // class variables
    70 LoadedLibraryModule LoadedLibraries::tab[MAX_MODULES];
    71 int LoadedLibraries::num_loaded = 0;
    73 // Checks whether the address p points to any of the loaded code segments.
    74 // If it does, returns the LoadedLibraryModule entry. If not, returns NULL.
    75 // static
    76 const LoadedLibraryModule* LoadedLibraries::find_for_text_address(const unsigned char* p) {
    78   if (num_loaded == 0) {
    79     reload();
    80   }
    81   for (int i = 0; i < num_loaded; i++) {
    82     if (tab[i].is_in_text(p)) {
    83       return &tab[i];
    84     }
    85   }
    86   return NULL;
    87 }
    89 // Checks whether the address p points to any of the loaded data segments.
    90 // If it does, returns the LoadedLibraryModule entry. If not, returns NULL.
    91 // static
    92 const LoadedLibraryModule* LoadedLibraries::find_for_data_address(const unsigned char* p) {
    93   if (num_loaded == 0) {
    94     reload();
    95   }
    96   for (int i = 0; i < num_loaded; i++) {
    97     if (tab[i].is_in_data(p)) {
    98       return &tab[i];
    99     }
   100   }
   101   return NULL;
   102 }
   104 // Rebuild the internal table of LoadedLibraryModule objects
   105 // static
   106 void LoadedLibraries::reload() {
   108   ThreadCritical cs;
   110   // discard old content
   111   num_loaded = 0;
   113   // Call loadquery(L_GETINFO..) to get a list of all loaded Dlls from AIX.
   114   size_t buf_size = 4096;
   115   char* loadquery_buf = AllocateHeap(buf_size, mtInternal);
   117   while(loadquery(L_GETINFO, loadquery_buf, buf_size) == -1) {
   118     if (errno == ENOMEM) {
   119       buf_size *= 2;
   120       loadquery_buf = ReallocateHeap(loadquery_buf, buf_size, mtInternal);
   121     } else {
   122       FreeHeap(loadquery_buf);
   123       // Ensure that the uintptr_t pointer is valid
   124       assert(errno != EFAULT, "loadquery: Invalid uintptr_t in info buffer.");
   125       fprintf(stderr, "loadquery failed (%d %s)", errno, strerror(errno));
   126       return;
   127     }
   128   }
   130   // Iterate over the loadquery result. For details see sys/ldr.h on AIX.
   131   const struct ld_info* p = (struct ld_info*) loadquery_buf;
   133   // Ensure we have all loaded libs.
   134   bool all_loaded = false;
   135   while(num_loaded < MAX_MODULES) {
   136     LoadedLibraryModule& mod = tab[num_loaded];
   137     mod.text_from = (const unsigned char*) p->ldinfo_textorg;
   138     mod.text_to   = (const unsigned char*) (((char*)p->ldinfo_textorg) + p->ldinfo_textsize);
   139     mod.data_from = (const unsigned char*) p->ldinfo_dataorg;
   140     mod.data_to   = (const unsigned char*) (((char*)p->ldinfo_dataorg) + p->ldinfo_datasize);
   141     sprintf(mod.fullpath, "%.*s", sizeof(mod.fullpath), p->ldinfo_filename);
   142     // do we have a member name as well (see ldr.h)?
   143     const char* p_mbr_name = p->ldinfo_filename + strlen(p->ldinfo_filename) + 1;
   144     if (*p_mbr_name) {
   145       sprintf(mod.membername, "%.*s", sizeof(mod.membername), p_mbr_name);
   146     } else {
   147       mod.membername[0] = '\0';
   148     }
   150     // fill in the short name
   151     const char* p_slash = strrchr(mod.fullpath, '/');
   152     if (p_slash) {
   153       sprintf(mod.shortname, "%.*s", sizeof(mod.shortname), p_slash + 1);
   154     } else {
   155       sprintf(mod.shortname, "%.*s", sizeof(mod.shortname), mod.fullpath);
   156     }
   157     num_loaded ++;
   159     // next entry...
   160     if (p->ldinfo_next) {
   161       p = (struct ld_info*)(((char*)p) + p->ldinfo_next);
   162     } else {
   163       all_loaded = true;
   164       break;
   165     }
   166   }
   168   FreeHeap(loadquery_buf);
   170   // Ensure we have all loaded libs
   171   assert(all_loaded, "loadquery returned more entries then expected. Please increase MAX_MODULES");
   173 } // end LoadedLibraries::reload()
   176 // output loaded libraries table
   177 //static
   178 void LoadedLibraries::print(outputStream* os) {
   180   for (int i = 0; i < num_loaded; i++) {
   181     tab[i].print(os);
   182   }
   184 }

mercurial