< prev index next >

src/share/vm/classfile/sharedPathsMiscInfo.cpp

Print this page
rev 13180 : imported patch 8181917-refactor-ul-logstream


  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classLoader.hpp"
  27 #include "classfile/classLoaderData.inline.hpp"
  28 #include "classfile/sharedPathsMiscInfo.hpp"
  29 #include "logging/log.hpp"

  30 #include "memory/allocation.inline.hpp"
  31 #include "memory/metaspaceShared.hpp"
  32 #include "memory/resourceArea.hpp"
  33 #include "runtime/arguments.hpp"
  34 #include "utilities/ostream.hpp"
  35 
  36 void SharedPathsMiscInfo::add_path(const char* path, int type) {
  37   log_info(class, path)("type=%s ", type_name(type));
  38   ClassLoader::trace_class_path("add misc shared path ", path);
  39   write(path, strlen(path) + 1);
  40   write_jint(jint(type));
  41 }
  42 
  43 void SharedPathsMiscInfo::ensure_size(size_t needed_bytes) {
  44   assert(_allocated, "cannot modify buffer during validation.");
  45   int used = get_used_bytes();
  46   int target = used + int(needed_bytes);
  47   if (target > _buf_size) {
  48     _buf_size = _buf_size * 2 + (int)needed_bytes;
  49     _buf_start = REALLOC_C_HEAP_ARRAY(char, _buf_start, _buf_size, mtClass);


  56   ensure_size(size);
  57   memcpy(_cur_ptr, ptr, size);
  58   _cur_ptr += size;
  59 }
  60 
  61 bool SharedPathsMiscInfo::read(void* ptr, size_t size) {
  62   if (_cur_ptr + size <= _end_ptr) {
  63     memcpy(ptr, _cur_ptr, size);
  64     _cur_ptr += size;
  65     return true;
  66   }
  67   return false;
  68 }
  69 
  70 bool SharedPathsMiscInfo::fail(const char* msg, const char* name) {
  71   ClassLoader::trace_class_path(msg, name);
  72   MetaspaceShared::set_archive_loading_failed();
  73   return false;
  74 }
  75 
  76 void SharedPathsMiscInfo::print_path(int type, const char* path) {
  77   ResourceMark rm;
  78   outputStream* out = Log(class, path)::info_stream();
  79   switch (type) {
  80   case BOOT:
  81     out->print("Expecting BOOT path=%s", path);
  82     break;
  83   case NON_EXIST:
  84     out->print("Expecting that %s does not exist", path);
  85     break;
  86   default:
  87     ShouldNotReachHere();
  88   }
  89 }
  90 
  91 bool SharedPathsMiscInfo::check() {
  92   // The whole buffer must be 0 terminated so that we can use strlen and strcmp
  93   // without fear.
  94   _end_ptr -= sizeof(jint);
  95   if (_cur_ptr >= _end_ptr) {
  96     return fail("Truncated archive file header");
  97   }
  98   if (*_end_ptr != 0) {
  99     return fail("Corrupted archive file header");
 100   }
 101 
 102   while (_cur_ptr < _end_ptr) {
 103     jint type;
 104     const char* path = _cur_ptr;
 105     _cur_ptr += strlen(path) + 1;
 106     if (!read_jint(&type)) {
 107       return fail("Corrupted archive file header");
 108     }
 109     log_info(class, path)("type=%s ", type_name(type));
 110     print_path(type, path);





 111     if (!check(type, path)) {
 112       if (!PrintSharedArchiveAndExit) {
 113         return false;
 114       }
 115     } else {
 116       ClassLoader::trace_class_path("ok");
 117     }
 118   }
 119 
 120   return true;
 121 }
 122 
 123 bool SharedPathsMiscInfo::check(jint type, const char* path) {
 124   switch (type) {
 125   case BOOT:
 126     if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) {
 127       return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath());
 128     }
 129     break;
 130   case NON_EXIST:


  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  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/classLoader.hpp"
  27 #include "classfile/classLoaderData.inline.hpp"
  28 #include "classfile/sharedPathsMiscInfo.hpp"
  29 #include "logging/log.hpp"
  30 #include "logging/logStream.hpp"
  31 #include "memory/allocation.inline.hpp"
  32 #include "memory/metaspaceShared.hpp"
  33 #include "memory/resourceArea.hpp"
  34 #include "runtime/arguments.hpp"
  35 #include "utilities/ostream.hpp"
  36 
  37 void SharedPathsMiscInfo::add_path(const char* path, int type) {
  38   log_info(class, path)("type=%s ", type_name(type));
  39   ClassLoader::trace_class_path("add misc shared path ", path);
  40   write(path, strlen(path) + 1);
  41   write_jint(jint(type));
  42 }
  43 
  44 void SharedPathsMiscInfo::ensure_size(size_t needed_bytes) {
  45   assert(_allocated, "cannot modify buffer during validation.");
  46   int used = get_used_bytes();
  47   int target = used + int(needed_bytes);
  48   if (target > _buf_size) {
  49     _buf_size = _buf_size * 2 + (int)needed_bytes;
  50     _buf_start = REALLOC_C_HEAP_ARRAY(char, _buf_start, _buf_size, mtClass);


  57   ensure_size(size);
  58   memcpy(_cur_ptr, ptr, size);
  59   _cur_ptr += size;
  60 }
  61 
  62 bool SharedPathsMiscInfo::read(void* ptr, size_t size) {
  63   if (_cur_ptr + size <= _end_ptr) {
  64     memcpy(ptr, _cur_ptr, size);
  65     _cur_ptr += size;
  66     return true;
  67   }
  68   return false;
  69 }
  70 
  71 bool SharedPathsMiscInfo::fail(const char* msg, const char* name) {
  72   ClassLoader::trace_class_path(msg, name);
  73   MetaspaceShared::set_archive_loading_failed();
  74   return false;
  75 }
  76 
  77 void SharedPathsMiscInfo::print_path(outputStream* out, int type, const char* path) {


  78   switch (type) {
  79   case BOOT:
  80     out->print("Expecting BOOT path=%s", path);
  81     break;
  82   case NON_EXIST:
  83     out->print("Expecting that %s does not exist", path);
  84     break;
  85   default:
  86     ShouldNotReachHere();
  87   }
  88 }
  89 
  90 bool SharedPathsMiscInfo::check() {
  91   // The whole buffer must be 0 terminated so that we can use strlen and strcmp
  92   // without fear.
  93   _end_ptr -= sizeof(jint);
  94   if (_cur_ptr >= _end_ptr) {
  95     return fail("Truncated archive file header");
  96   }
  97   if (*_end_ptr != 0) {
  98     return fail("Corrupted archive file header");
  99   }
 100 
 101   while (_cur_ptr < _end_ptr) {
 102     jint type;
 103     const char* path = _cur_ptr;
 104     _cur_ptr += strlen(path) + 1;
 105     if (!read_jint(&type)) {
 106       return fail("Corrupted archive file header");
 107     }
 108     LogTarget(Info, class, path) lt;
 109     if (lt.is_enabled()) {
 110       lt.print("type=%s ", type_name(type));
 111       LogStream ls(lt);
 112       print_path(&ls, type, path);
 113       ls.cr();
 114     }
 115     if (!check(type, path)) {
 116       if (!PrintSharedArchiveAndExit) {
 117         return false;
 118       }
 119     } else {
 120       ClassLoader::trace_class_path("ok");
 121     }
 122   }
 123 
 124   return true;
 125 }
 126 
 127 bool SharedPathsMiscInfo::check(jint type, const char* path) {
 128   switch (type) {
 129   case BOOT:
 130     if (os::file_name_strcmp(path, Arguments::get_sysclasspath()) != 0) {
 131       return fail("[BOOT classpath mismatch, actual =", Arguments::get_sysclasspath());
 132     }
 133     break;
 134   case NON_EXIST:
< prev index next >