PrivateInvokeTest.java revision 5465
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* 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
* @summary white-box testing of method handle sub-primitives
* @run junit test.java.lang.invoke.PrivateInvokeTest
*/
public class PrivateInvokeTest {
// Utility functions
private static final int
REF_getField = 1,
REF_getStatic = 2,
REF_putField = 3,
REF_putStatic = 4,
REF_invokeVirtual = 5,
REF_invokeStatic = 6,
REF_invokeSpecial = 7,
REF_newInvokeSpecial = 8,
REF_invokeInterface = 9,
REF_LIMIT = 10,
private static final String[] REF_KIND_NAMES = {
"MH::invokeBasic",
"REF_getField", "REF_getStatic", "REF_putField", "REF_putStatic",
"REF_invokeVirtual", "REF_invokeStatic", "REF_invokeSpecial",
"REF_newInvokeSpecial", "REF_invokeInterface"
};
private int verbose;
//{ verbose = 99; } // for debugging
{
}
private static int referenceKind(Method m) {
return REF_invokeStatic;
else if (m.getDeclaringClass().isInterface())
return REF_invokeInterface;
return REF_invokeSpecial;
else
return REF_invokeVirtual;
}
if (btype.hasPrimitives()) {
if (type == boolean.class ||
type == byte.class ||
type == char.class ||
type == short.class) {
type = int.class;
if (i < 0)
else
}
}
}
return btype;
}
try {
} catch (NoSuchMethodException ex) {
}
try {
} catch (NoSuchMethodException ex) {
throw new IllegalArgumentException(ex);
}
}
try {
return mh;
} catch (IllegalAccessException ex) {
throw new IllegalArgumentException(ex);
}
}
private static final Lookup DIRECT_INVOKER_LOOKUP;
private static final Class<?> MEMBER_NAME_CLASS;
private static final MethodHandle MH_INTERNAL_MEMBER_NAME;
private static final MethodHandle MH_DEBUG_STRING;
static {
try {
// This is white box testing. Use reflection to grab private implementation bits.
// This unit test will fail if a security manager is installed.
magicLookup.setAccessible(true);
// Forbidden fruit...
MEMBER_NAME_CLASS = Class.forName("java.lang.invoke.MemberName", false, MethodHandle.class.getClassLoader());
} catch (ReflectiveOperationException ex) {
}
}
try {
}
}
try {
}
}
}
boolean isStatic;
isStatic = false;
isStatic = true;
} else {
}
//System.out.println("directInvoker = "+name+mtype);
try {
if (isStatic)
return DIRECT_INVOKER_LOOKUP
else
return DIRECT_INVOKER_LOOKUP
} catch (ReflectiveOperationException ex) {
throw new IllegalArgumentException(ex);
}
}
}
try {
throw new IllegalArgumentException(ex);
}
}
try {
throw new IllegalArgumentException(ex);
}
}
private int counter;
final int n = ++counter;
}
}
return args;
}
}
if (n >= 0)
else
}
return res;
}
return res;
}
assert(s.startsWith(prefix));
}
public void printCounts() {
final int count = refKindTestCounts[i];
if (count == 0) {
continue;
}
if (verbose >= 0)
}
if (verbose >= 0)
}
// Test subjects
}
return res;
}
new PrivateInvokeTest().run();
}
testFirst();
}
@Test
if (true) return; // nothing here
try {
} finally {
}
}
@Test
public void testInvokeDirect() {
}
void testInvokeDirect(Method m) {
final int refKind = referenceKind(m);
testInvokeDirect(m, refKind);
}
if (verbose >= 1)
// res1 comes from java.lang.reflect.Method::invoke
if (verbose >= 1)
// res2 comes from java.lang.invoke.MethodHandle::invoke
// Try a detuned invoker.
}
// Try a detuned invoker.
}
if (false) {
// this can crash the JVM
testInvokeVia("generic DMH invoker", refKind, directInvoker(refKind, mtype.generic()), mh, res1, args);
}
}
void testInvokeVia(String kind, int refKind, MethodHandle invoker, MethodHandle mh, Object res1, Object... args) {
if (refKind == REF_MH_invokeBasic)
else
if (verbose >= 2) {
}
}
}