3792N/A/*
5440N/A * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3792N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3792N/A *
3792N/A * This code is free software; you can redistribute it and/or modify it
3792N/A * under the terms of the GNU General Public License version 2 only, as
3792N/A * published by the Free Software Foundation. Oracle designates this
3792N/A * particular file as subject to the "Classpath" exception as provided
3792N/A * by Oracle in the LICENSE file that accompanied this code.
3792N/A *
3792N/A * This code is distributed in the hope that it will be useful, but WITHOUT
3792N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3792N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3792N/A * version 2 for more details (a copy is included in the LICENSE file that
3792N/A * accompanied this code).
3792N/A *
3792N/A * You should have received a copy of the GNU General Public License version
3792N/A * 2 along with this work; if not, write to the Free Software Foundation,
3792N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
3792N/A *
3792N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
3792N/A * or visit www.oracle.com if you need additional information or have any
3792N/A * questions.
3792N/A */
3792N/A
3793N/Apackage java.lang.invoke;
3792N/A
4278N/Aimport java.security.AccessController;
4278N/Aimport java.security.PrivilegedAction;
5459N/Aimport sun.misc.Unsafe;
4278N/A
3792N/A/**
3792N/A * This class consists exclusively of static names internal to the
3792N/A * method handle implementation.
3793N/A * Usage: {@code import static java.lang.invoke.MethodHandleStatics.*}
3792N/A * @author John Rose, JSR 292 EG
3792N/A */
3792N/A/*non-public*/ class MethodHandleStatics {
3792N/A
3792N/A private MethodHandleStatics() { } // do not instantiate
3792N/A
5459N/A static final Unsafe UNSAFE = Unsafe.getUnsafe();
5459N/A
4278N/A static final boolean DEBUG_METHOD_HANDLE_NAMES;
5459N/A static final boolean DUMP_CLASS_FILES;
5459N/A static final boolean TRACE_INTERPRETER;
5459N/A static final boolean TRACE_METHOD_LINKAGE;
5459N/A static final Integer COMPILE_THRESHOLD;
4278N/A static {
5459N/A final Object[] values = { false, false, false, false, null };
4278N/A AccessController.doPrivileged(new PrivilegedAction<Void>() {
4278N/A public Void run() {
4278N/A values[0] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DEBUG_NAMES");
5459N/A values[1] = Boolean.getBoolean("java.lang.invoke.MethodHandle.DUMP_CLASS_FILES");
5459N/A values[2] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_INTERPRETER");
5459N/A values[3] = Boolean.getBoolean("java.lang.invoke.MethodHandle.TRACE_METHOD_LINKAGE");
5459N/A values[4] = Integer.getInteger("java.lang.invoke.MethodHandle.COMPILE_THRESHOLD");
4278N/A return null;
4278N/A }
4278N/A });
4278N/A DEBUG_METHOD_HANDLE_NAMES = (Boolean) values[0];
5459N/A DUMP_CLASS_FILES = (Boolean) values[1];
5459N/A TRACE_INTERPRETER = (Boolean) values[2];
5459N/A TRACE_METHOD_LINKAGE = (Boolean) values[3];
5459N/A COMPILE_THRESHOLD = (Integer) values[4];
4278N/A }
4245N/A
3792N/A /*non-public*/ static String getNameString(MethodHandle target, MethodType type) {
3792N/A if (type == null)
3792N/A type = target.type();
3792N/A MemberName name = null;
3792N/A if (target != null)
5459N/A name = target.internalMemberName();
3792N/A if (name == null)
3792N/A return "invoke" + type;
3792N/A return name.getName() + type;
3792N/A }
3792N/A
3792N/A /*non-public*/ static String getNameString(MethodHandle target, MethodHandle typeHolder) {
3792N/A return getNameString(target, typeHolder == null ? (MethodType) null : typeHolder.type());
3792N/A }
3792N/A
3792N/A /*non-public*/ static String getNameString(MethodHandle target) {
3792N/A return getNameString(target, (MethodType) null);
3792N/A }
3792N/A
3792N/A /*non-public*/ static String addTypeString(Object obj, MethodHandle target) {
3792N/A String str = String.valueOf(obj);
3792N/A if (target == null) return str;
3792N/A int paren = str.indexOf('(');
3792N/A if (paren >= 0) str = str.substring(0, paren);
3792N/A return str + target.type();
3792N/A }
3792N/A
3792N/A // handy shared exception makers (they simplify the common case code)
5465N/A /*non-public*/ static InternalError newInternalError(String message, Throwable cause) {
5465N/A InternalError e = new InternalError(message);
5465N/A e.initCause(cause);
5465N/A return e;
5465N/A }
5465N/A /*non-public*/ static InternalError newInternalError(Throwable cause) {
5465N/A InternalError e = new InternalError();
5465N/A e.initCause(cause);
5465N/A return e;
5465N/A }
3792N/A /*non-public*/ static RuntimeException newIllegalStateException(String message) {
3792N/A return new IllegalStateException(message);
3792N/A }
3792N/A /*non-public*/ static RuntimeException newIllegalStateException(String message, Object obj) {
3792N/A return new IllegalStateException(message(message, obj));
3792N/A }
3792N/A /*non-public*/ static RuntimeException newIllegalArgumentException(String message) {
3792N/A return new IllegalArgumentException(message);
3792N/A }
3792N/A /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj) {
3792N/A return new IllegalArgumentException(message(message, obj));
3792N/A }
4183N/A /*non-public*/ static RuntimeException newIllegalArgumentException(String message, Object obj, Object obj2) {
4183N/A return new IllegalArgumentException(message(message, obj, obj2));
4183N/A }
5440N/A /*non-public*/ static Error uncaughtException(Throwable ex) {
5465N/A throw newInternalError("uncaught exception", ex);
3792N/A }
5459N/A static Error NYI() {
5459N/A throw new AssertionError("NYI");
5459N/A }
3792N/A private static String message(String message, Object obj) {
3792N/A if (obj != null) message = message + ": " + obj;
3792N/A return message;
3792N/A }
4183N/A private static String message(String message, Object obj, Object obj2) {
4183N/A if (obj != null || obj2 != null) message = message + ": " + obj + ", " + obj2;
4183N/A return message;
4183N/A }
3792N/A}