--- old/src/share/vm/classfile/vmSymbols.hpp 2015-05-12 19:27:40.830323518 +0300 +++ new/src/share/vm/classfile/vmSymbols.hpp 2015-05-12 19:27:40.684320701 +0300 @@ -325,6 +325,7 @@ template(reference_lock_name, "lock") \ template(reference_discovered_name, "discovered") \ template(run_finalization_name, "runFinalization") \ + template(print_finalization_queue_name, "printFinalizationQueue") \ template(run_finalizers_on_exit_name, "runFinalizersOnExit") \ template(dispatchUncaughtException_name, "dispatchUncaughtException") \ template(initializeSystemClass_name, "initializeSystemClass") \ --- old/src/share/vm/services/diagnosticCommand.cpp 2015-05-12 19:27:41.268331972 +0300 +++ new/src/share/vm/services/diagnosticCommand.cpp 2015-05-12 19:27:41.125329212 +0300 @@ -54,6 +54,8 @@ DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); + DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); #if INCLUDE_SERVICES // Heap dumping/inspection supported DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(DCmd_Source_Internal | DCmd_Source_AttachAPI, true, false)); DCmdFactory::register_DCmdFactory(new DCmdFactoryImpl(full_export, true, false)); @@ -285,6 +287,25 @@ vmSymbols::void_method_signature(), CHECK); } +void HeapInfoDCmd::execute(DCmdSource source, TRAPS) { + Universe::heap()->print_on(output()); +} + +void FinalizerInfoDCmd::execute(DCmdSource source, TRAPS) { + output()->print_cr("Unreachable instances awaiting finalization"); + + Klass *k = SystemDictionary::Finalizer_klass(); + instanceKlassHandle klass(THREAD, k); + JavaValue result(T_OBJECT); + JavaCalls::call_static(&result, klass, + vmSymbols::print_finalization_queue_name(), + vmSymbols::void_string_signature(), CHECK); + + oop result_oop = (oop) result.get_jobject(); + char *result_str = java_lang_String::as_utf8_string(result_oop); + output()->print_cr("%s", result_str); +} + #if INCLUDE_SERVICES // Heap dumping/inspection supported HeapDumpDCmd::HeapDumpDCmd(outputStream* output, bool heap) : DCmdWithParser(output, heap), --- old/src/share/vm/services/diagnosticCommand.hpp 2015-05-12 19:27:41.697340252 +0300 +++ new/src/share/vm/services/diagnosticCommand.hpp 2015-05-12 19:27:41.553337473 +0300 @@ -198,6 +198,46 @@ virtual void execute(DCmdSource source, TRAPS); }; +class HeapInfoDCmd : public DCmd { +public: + HeapInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } + static const char* name() { return "GC.heap_info"; } + static const char* description() { + return "Provide generic Java heap information."; + } + static const char* impact() { + return "Low"; + } + static int num_arguments() { return 0; } + static const JavaPermission permission() { + JavaPermission p = {"java.lang.management.ManagementPermission", + "monitor", NULL}; + return p; + } + + virtual void execute(DCmdSource source, TRAPS); +}; + +class FinalizerInfoDCmd : public DCmd { +public: + FinalizerInfoDCmd(outputStream* output, bool heap) : DCmd(output, heap) { } + static const char* name() { return "GC.finalizer_info"; } + static const char* description() { + return "Provide information about Java finalization queue."; + } + static const char* impact() { + return "Low"; + } + static int num_arguments() { return 0; } + static const JavaPermission permission() { + JavaPermission p = {"java.lang.management.ManagementPermission", + "monitor", NULL}; + return p; + } + + virtual void execute(DCmdSource source, TRAPS); +}; + #if INCLUDE_SERVICES // Heap dumping supported // See also: dump_heap in attachListener.cpp class HeapDumpDCmd : public DCmdWithParser { --- /dev/null 2015-05-12 15:41:00.858978672 +0300 +++ new/test/serviceability/dcmd/gc/FinalizerInfoTest.java 2015-05-12 19:27:41.981345734 +0300 @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import org.testng.annotations.Test; +import org.testng.Assert; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.ReentrantLock; + +import com.oracle.java.testlibrary.dcmd.CommandExecutor; +import com.oracle.java.testlibrary.dcmd.PidJcmdExecutor; + +/* + * @test + * @summary + * @library /testlibrary + * @build com.oracle.java.testlibrary.* + * @build com.oracle.java.testlibrary.dcmd.* + * @run testng FinalizerInfoTest + */ +public class FinalizerInfoTest { + static ReentrantLock lock = new ReentrantLock(); + static volatile int wasInitialized = 0; + static volatile int wasTrapped = 0; + static final String cmd = "GC.finalizer_info"; + static final int objectsCount = 1000; + + class MyObject { + public MyObject() { + // Make sure object allocation/deallocation is not optimized out + wasInitialized += 1; + } + + protected void finalize() { + // Trap the object in a finalization queue + wasTrapped += 1; + lock.lock(); + } + } + + public void run(CommandExecutor executor) { + lock.lock(); + for(int i = 0; i < objectsCount; ++i) { + new MyObject(); + } + while(wasInitialized != objectsCount); + System.out.println("Objects intialized: " + wasInitialized); + while(wasTrapped < 1) { + System.gc(); + } + executor.execute(cmd); + lock.unlock(); + } + + @Test + public void pid() { + run(new PidJcmdExecutor()); + } +} --- /dev/null 2015-05-12 15:41:00.858978672 +0300 +++ new/test/serviceability/dcmd/gc/HeapInfoTest.java 2015-05-12 19:27:42.384353513 +0300 @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +import org.testng.annotations.Test; +import org.testng.Assert; + +import java.io.IOException; + +import com.oracle.java.testlibrary.JDKToolFinder; +import com.oracle.java.testlibrary.OutputAnalyzer; +import com.oracle.java.testlibrary.dcmd.CommandExecutor; +import com.oracle.java.testlibrary.dcmd.PidJcmdExecutor; + +/* + * @test + * @summary Test of diagnostic command GC.heap_info + * @library /testlibrary + * @build com.oracle.java.testlibrary.* + * @build com.oracle.java.testlibrary.dcmd.* + * @run testng HeapInfoTest + */ +public class HeapInfoTest { + public void run(CommandExecutor executor) { + String cmd = "GC.heap_info"; + executor.execute(cmd); + } + + @Test + public void pid() { + run(new PidJcmdExecutor()); + } +} +