Path: blob/master/test/jdk/com/sun/management/DiagnosticCommandMBean/DcmdMBeanTestCheckJni.java
41155 views
/*1* Copyright (c) 2021, Red Hat, Inc.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 825883626* @summary JNI local refs exceed capacity getDiagnosticCommandInfo27* @library /test/lib28* @run main/othervm DcmdMBeanTestCheckJni29*/3031import java.lang.management.ManagementFactory;32import javax.management.MBeanServer;33import javax.management.ObjectName;34import javax.management.MBeanServerConnection;35import javax.management.remote.JMXConnectorFactory;36import javax.management.remote.JMXConnector;37import javax.management.remote.JMXConnectorServerFactory;38import javax.management.remote.JMXServiceURL;39import javax.management.remote.JMXConnectorServer;4041import jdk.test.lib.process.OutputAnalyzer;42import jdk.test.lib.process.ProcessTools;4344public class DcmdMBeanTestCheckJni {4546public static void main(String[] args) throws Exception {47OutputAnalyzer out = ProcessTools.executeTestJvm(48"-Xcheck:jni",49DcmdMBeanRunner.class.getName());50out.shouldNotMatch("WARNING: JNI local refs: \\d+, exceeds capacity: \\d+\\s+" +51"at com.sun.management.internal.DiagnosticCommandImpl.getDiagnosticCommandInfo")52.shouldContain("DcmdMBeanRunner COMPLETE")53.shouldHaveExitValue(0);54}5556}5758class DcmdMBeanRunner {5960private static final String HOTSPOT_DIAGNOSTIC_MXBEAN_NAME =61"com.sun.management:type=DiagnosticCommand";6263public static void main(String[] args) throws Exception {64MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();65JMXServiceURL url = new JMXServiceURL("rmi", null, 0);66JMXConnectorServer cs = null;67JMXConnector cc = null;68try {69cs = JMXConnectorServerFactory.newJMXConnectorServer(url, null, mbs);70cs.start();71JMXServiceURL addr = cs.getAddress();72cc = JMXConnectorFactory.connect(addr);73MBeanServerConnection mbsc = cc.getMBeanServerConnection();74ObjectName name = new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME);75System.out.println("DiagnosticCommand MBean: " + name);76System.out.println("DcmdMBeanRunner COMPLETE");77} finally {78try {79cc.close();80cs.stop();81} catch (Exception e) { /* ignored */ }82}83}84}858687