2014-09-10 11:27:33 +00:00
|
|
|
/*
|
2016-01-12 10:11:21 +00:00
|
|
|
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved.
|
2014-09-10 11:27:33 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @test CodelistTest
|
|
|
|
* @bug 8054889
|
2015-01-30 19:00:57 +00:00
|
|
|
* @library /testlibrary
|
2015-03-26 15:36:56 +00:00
|
|
|
* @modules java.base/sun.misc
|
|
|
|
* java.compiler
|
|
|
|
* java.management
|
|
|
|
* jdk.jvmstat/sun.jvmstat.monitor
|
2015-05-04 14:30:07 +00:00
|
|
|
* @build jdk.test.lib.*
|
|
|
|
* @build jdk.test.lib.dcmd.*
|
2015-01-30 19:00:57 +00:00
|
|
|
* @build MethodIdentifierParser
|
|
|
|
* @run testng CodelistTest
|
2014-09-10 11:27:33 +00:00
|
|
|
* @summary Test of diagnostic command Compiler.codelist
|
|
|
|
*/
|
|
|
|
|
2015-01-30 19:00:57 +00:00
|
|
|
import org.testng.annotations.Test;
|
|
|
|
import org.testng.Assert;
|
|
|
|
|
2015-05-04 14:30:07 +00:00
|
|
|
import jdk.test.lib.OutputAnalyzer;
|
|
|
|
import jdk.test.lib.dcmd.CommandExecutor;
|
|
|
|
import jdk.test.lib.dcmd.JMXExecutor;
|
2015-01-30 19:00:57 +00:00
|
|
|
|
2014-09-10 11:27:33 +00:00
|
|
|
import java.lang.reflect.Method;
|
|
|
|
|
|
|
|
public class CodelistTest {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This test calls Jcmd (diagnostic command tool) Compiler.codelist and then parses the output,
|
|
|
|
* making sure that the first methods in the list is valid by reflection.
|
|
|
|
*
|
|
|
|
* Output example:
|
|
|
|
*
|
|
|
|
* 6 0 java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V [0x00007f7b49200910, 0x00007f7b49200aa0 - 0x00007f7b49200d30]
|
|
|
|
* 2 3 java.lang.String.indexOf(II)I [0x00007f7b49200d90, 0x00007f7b49200f60 - 0x00007f7b49201490]
|
|
|
|
* 7 3 java.lang.Math.min(II)I [0x00007f7b4922f010, 0x00007f7b4922f180 - 0x00007f7b4922f338]
|
|
|
|
* 8 3 java.lang.String.equals(Ljava/lang/Object;)Z [0x00007f7b4922fb10, 0x00007f7b4922fd40 - 0x00007f7b49230698]
|
|
|
|
* 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
|
|
|
|
* 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2015-01-30 19:00:57 +00:00
|
|
|
public void run(CommandExecutor executor) {
|
2014-09-10 11:27:33 +00:00
|
|
|
int ok = 0;
|
|
|
|
int fail = 0;
|
|
|
|
|
|
|
|
// Get output from dcmd (diagnostic command)
|
2015-01-30 19:00:57 +00:00
|
|
|
OutputAnalyzer output = executor.execute("Compiler.codelist");
|
2014-09-10 11:27:33 +00:00
|
|
|
|
|
|
|
// Grab a method name from the output
|
|
|
|
int count = 0;
|
|
|
|
|
2015-01-30 19:00:57 +00:00
|
|
|
for (String line : output.asLines()) {
|
2014-09-10 11:27:33 +00:00
|
|
|
count++;
|
|
|
|
|
|
|
|
String[] parts = line.split(" ");
|
|
|
|
// int compileID = Integer.parseInt(parts[0]);
|
|
|
|
// int compileLevel = Integer.parseInt(parts[1]);
|
|
|
|
String methodPrintedInLogFormat = parts[2];
|
|
|
|
|
2016-01-12 10:11:21 +00:00
|
|
|
// skip inits, clinits, methodHandles and getUnsafe -
|
|
|
|
// they can not be reflected
|
2014-09-10 11:27:33 +00:00
|
|
|
if (methodPrintedInLogFormat.contains("<init>")) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (methodPrintedInLogFormat.contains("<clinit>")) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-30 08:22:58 +00:00
|
|
|
if (methodPrintedInLogFormat.contains("MethodHandle")) {
|
|
|
|
continue;
|
|
|
|
}
|
2015-09-14 11:26:29 +00:00
|
|
|
if (methodPrintedInLogFormat.contains("sun.misc.Unsafe.getUnsafe")) {
|
|
|
|
continue;
|
|
|
|
}
|
2016-01-12 10:11:21 +00:00
|
|
|
if (methodPrintedInLogFormat.contains("jdk.internal.misc.Unsafe.getUnsafe")) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-09-10 11:27:33 +00:00
|
|
|
|
|
|
|
MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat);
|
2015-01-30 19:00:57 +00:00
|
|
|
Method m = null;
|
2014-09-10 11:27:33 +00:00
|
|
|
try {
|
|
|
|
m = mf.getMethod();
|
|
|
|
} catch (NoSuchMethodException e) {
|
|
|
|
m = null;
|
2015-01-30 19:00:57 +00:00
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
Assert.fail("Test error: Caught unexpected exception", e);
|
2014-09-10 11:27:33 +00:00
|
|
|
}
|
|
|
|
if (m == null) {
|
2015-01-30 19:00:57 +00:00
|
|
|
Assert.fail("Test failed on: " + methodPrintedInLogFormat);
|
2014-09-10 11:27:33 +00:00
|
|
|
}
|
|
|
|
if (count > 10) {
|
|
|
|
// Testing 10 entries is enough. Lets not waste time.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-01-30 19:00:57 +00:00
|
|
|
|
|
|
|
@Test
|
|
|
|
public void jmx() {
|
|
|
|
run(new JMXExecutor());
|
|
|
|
}
|
2014-09-10 11:27:33 +00:00
|
|
|
}
|