< prev index next >

src/hotspot/share/cds/classListWriter.cpp

Print this page

  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  */
 24 
 25 #include "cds/cds_globals.hpp"

 26 #include "cds/classListWriter.hpp"
 27 #include "cds/lambdaFormInvokers.inline.hpp"
 28 #include "classfile/classFileStream.hpp"
 29 #include "classfile/classLoader.hpp"
 30 #include "classfile/classLoaderData.hpp"
 31 #include "classfile/classLoaderDataGraph.hpp"
 32 #include "classfile/moduleEntry.hpp"

 33 #include "classfile/systemDictionaryShared.hpp"
 34 #include "memory/resourceArea.hpp"
 35 #include "oops/constantPool.inline.hpp"
 36 #include "oops/instanceKlass.hpp"

 37 #include "runtime/mutexLocker.hpp"
 38 
 39 fileStream* ClassListWriter::_classlist_file = nullptr;
 40 
 41 void ClassListWriter::init() {
 42   // For -XX:DumpLoadedClassList=<file> option
 43   if (DumpLoadedClassList != nullptr) {
 44     const char* list_name = make_log_name(DumpLoadedClassList, nullptr);
 45     _classlist_file = new(mtInternal)
 46                          fileStream(list_name);
 47     _classlist_file->print_cr("# NOTE: Do not modify this file.");
 48     _classlist_file->print_cr("#");
 49     _classlist_file->print_cr("# This file is generated via the -XX:DumpLoadedClassList=<class_list_file> option");
 50     _classlist_file->print_cr("# and is used at CDS archive dump time (see -Xshare:dump).");
 51     _classlist_file->print_cr("#");
 52     FREE_C_HEAP_ARRAY(char, list_name);
 53   }
 54 }
 55 
 56 void ClassListWriter::write(const InstanceKlass* k, const ClassFileStream* cfs) {

303     }
304   }
305 
306   if (print) {
307     outputStream* stream = _classlist_file;
308     stream->print("@cp %s", ik->name()->as_C_string());
309     for (int i = 0; i < list.length(); i++) {
310       if (list.at(i)) {
311         constantTag cp_tag = cp->tag_at(i).value();
312         assert(cp_tag.value() == JVM_CONSTANT_Class ||
313                cp_tag.value() == JVM_CONSTANT_Fieldref ||
314                cp_tag.value() == JVM_CONSTANT_Methodref||
315                cp_tag.value() == JVM_CONSTANT_InterfaceMethodref ||
316                cp_tag.value() == JVM_CONSTANT_InvokeDynamic, "sanity");
317         stream->print(" %d", i);
318       }
319     }
320     stream->cr();
321   }
322 }
















































  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  */
 24 
 25 #include "cds/cds_globals.hpp"
 26 #include "cds/classListParser.hpp"
 27 #include "cds/classListWriter.hpp"
 28 #include "cds/lambdaFormInvokers.inline.hpp"
 29 #include "classfile/classFileStream.hpp"
 30 #include "classfile/classLoader.hpp"
 31 #include "classfile/classLoaderData.hpp"
 32 #include "classfile/classLoaderDataGraph.hpp"
 33 #include "classfile/moduleEntry.hpp"
 34 #include "classfile/symbolTable.hpp"
 35 #include "classfile/systemDictionaryShared.hpp"
 36 #include "memory/resourceArea.hpp"
 37 #include "oops/constantPool.inline.hpp"
 38 #include "oops/instanceKlass.hpp"
 39 #include "runtime/javaCalls.hpp"
 40 #include "runtime/mutexLocker.hpp"
 41 
 42 fileStream* ClassListWriter::_classlist_file = nullptr;
 43 
 44 void ClassListWriter::init() {
 45   // For -XX:DumpLoadedClassList=<file> option
 46   if (DumpLoadedClassList != nullptr) {
 47     const char* list_name = make_log_name(DumpLoadedClassList, nullptr);
 48     _classlist_file = new(mtInternal)
 49                          fileStream(list_name);
 50     _classlist_file->print_cr("# NOTE: Do not modify this file.");
 51     _classlist_file->print_cr("#");
 52     _classlist_file->print_cr("# This file is generated via the -XX:DumpLoadedClassList=<class_list_file> option");
 53     _classlist_file->print_cr("# and is used at CDS archive dump time (see -Xshare:dump).");
 54     _classlist_file->print_cr("#");
 55     FREE_C_HEAP_ARRAY(char, list_name);
 56   }
 57 }
 58 
 59 void ClassListWriter::write(const InstanceKlass* k, const ClassFileStream* cfs) {

306     }
307   }
308 
309   if (print) {
310     outputStream* stream = _classlist_file;
311     stream->print("@cp %s", ik->name()->as_C_string());
312     for (int i = 0; i < list.length(); i++) {
313       if (list.at(i)) {
314         constantTag cp_tag = cp->tag_at(i).value();
315         assert(cp_tag.value() == JVM_CONSTANT_Class ||
316                cp_tag.value() == JVM_CONSTANT_Fieldref ||
317                cp_tag.value() == JVM_CONSTANT_Methodref||
318                cp_tag.value() == JVM_CONSTANT_InterfaceMethodref ||
319                cp_tag.value() == JVM_CONSTANT_InvokeDynamic, "sanity");
320         stream->print(" %d", i);
321       }
322     }
323     stream->cr();
324   }
325 }
326 
327 void ClassListWriter::write_loader_negative_lookup_cache_for(oop loader, const char* loader_type) {
328   TempNewSymbol method = SymbolTable::new_symbol("negativeLookupCacheContents");
329   TempNewSymbol signature = SymbolTable::new_symbol("()Ljava/lang/String;");
330 
331   EXCEPTION_MARK;
332   HandleMark hm(THREAD);
333 
334   JavaValue result(T_OBJECT);
335   JavaCalls::call_virtual(&result,
336                           Handle(THREAD, loader),
337                           loader->klass(),
338                           method,
339                           signature,
340                           CHECK);
341 
342   if (HAS_PENDING_EXCEPTION) {
343     log_warning(cds)("Error during BuiltinClassLoader::negativeLookupCacheContents() call for %s loader", loader_type);
344     CLEAR_PENDING_EXCEPTION;
345     return;
346   } else if (result.get_oop() == nullptr) {
347     return;
348   }
349 
350   ResourceMark rm;
351   const char* cache_contents = java_lang_String::as_utf8_string(result.get_oop());
352   log_debug(cds)("%s loader negative cache: %s", loader_type, cache_contents);
353 
354   outputStream* stream = _classlist_file;
355   const size_t buffer_size = strlen(ClassListParser::LOADER_NEGATIVE_CACHE_TAG) + 1 /* for space*/
356                     + strlen(loader_type) + 1 /* for space */ + strlen(cache_contents) + 1 /* for null character */;
357   char* buffer = NEW_C_HEAP_ARRAY(char, buffer_size, mtInternal);
358   _classlist_file->set_scratch_buffer(buffer, buffer_size);
359   MutexLocker lock2(ClassListFile_lock, Mutex::_no_safepoint_check_flag);
360   stream->print("%s %s %s", ClassListParser::LOADER_NEGATIVE_CACHE_TAG, loader_type, cache_contents);
361   stream->cr();
362   _classlist_file->set_scratch_buffer(nullptr, 0);
363 }
364 
365 void ClassListWriter::write_loader_negative_lookup_cache() {
366   if (!is_enabled()) {
367     return;
368   }
369 
370   write_loader_negative_lookup_cache_for(SystemDictionary::java_platform_loader(), "platform");
371   write_loader_negative_lookup_cache_for(SystemDictionary::java_system_loader(), "app");
372 }
< prev index next >