1/*
2 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.  Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26package java.lang.invoke;
27
28import jdk.internal.perf.PerfCounter;
29import jdk.internal.vm.annotation.DontInline;
30import jdk.internal.vm.annotation.Stable;
31import sun.invoke.util.Wrapper;
32
33import java.lang.annotation.ElementType;
34import java.lang.annotation.Retention;
35import java.lang.annotation.RetentionPolicy;
36import java.lang.annotation.Target;
37import java.lang.reflect.Method;
38import java.util.Arrays;
39import java.util.HashMap;
40
41import static java.lang.invoke.LambdaForm.BasicType.*;
42import static java.lang.invoke.MethodHandleNatives.Constants.REF_invokeStatic;
43import static java.lang.invoke.MethodHandleStatics.*;
44
45/**
46 * The symbolic, non-executable form of a method handle's invocation semantics.
47 * It consists of a series of names.
48 * The first N (N=arity) names are parameters,
49 * while any remaining names are temporary values.
50 * Each temporary specifies the application of a function to some arguments.
51 * The functions are method handles, while the arguments are mixes of
52 * constant values and local names.
53 * The result of the lambda is defined as one of the names, often the last one.
54 * <p>
55 * Here is an approximate grammar:
56 * <blockquote><pre>{@code
57 * LambdaForm = "(" ArgName* ")=>{" TempName* Result "}"
58 * ArgName = "a" N ":" T
59 * TempName = "t" N ":" T "=" Function "(" Argument* ");"
60 * Function = ConstantValue
61 * Argument = NameRef | ConstantValue
62 * Result = NameRef | "void"
63 * NameRef = "a" N | "t" N
64 * N = (any whole number)
65 * T = "L" | "I" | "J" | "F" | "D" | "V"
66 * }</pre></blockquote>
67 * Names are numbered consecutively from left to right starting at zero.
68 * (The letters are merely a taste of syntax sugar.)
69 * Thus, the first temporary (if any) is always numbered N (where N=arity).
70 * Every occurrence of a name reference in an argument list must refer to
71 * a name previously defined within the same lambda.
72 * A lambda has a void result if and only if its result index is -1.
73 * If a temporary has the type "V", it cannot be the subject of a NameRef,
74 * even though possesses a number.
75 * Note that all reference types are erased to "L", which stands for {@code Object}.
76 * All subword types (boolean, byte, short, char) are erased to "I" which is {@code int}.
77 * The other types stand for the usual primitive types.
78 * <p>
79 * Function invocation closely follows the static rules of the Java verifier.
80 * Arguments and return values must exactly match when their "Name" types are
81 * considered.
82 * Conversions are allowed only if they do not change the erased type.
83 * <ul>
84 * <li>L = Object: casts are used freely to convert into and out of reference types
85 * <li>I = int: subword types are forcibly narrowed when passed as arguments (see {@code explicitCastArguments})
86 * <li>J = long: no implicit conversions
87 * <li>F = float: no implicit conversions
88 * <li>D = double: no implicit conversions
89 * <li>V = void: a function result may be void if and only if its Name is of type "V"
90 * </ul>
91 * Although implicit conversions are not allowed, explicit ones can easily be
92 * encoded by using temporary expressions which call type-transformed identity functions.
93 * <p>
94 * Examples:
95 * <blockquote><pre>{@code
96 * (a0:J)=>{ a0 }
97 *     == identity(long)
98 * (a0:I)=>{ t1:V = System.out#println(a0); void }
99 *     == System.out#println(int)
100 * (a0:L)=>{ t1:V = System.out#println(a0); a0 }
101 *     == identity, with printing side-effect
102 * (a0:L, a1:L)=>{ t2:L = BoundMethodHandle#argument(a0);
103 *                 t3:L = BoundMethodHandle#target(a0);
104 *                 t4:L = MethodHandle#invoke(t3, t2, a1); t4 }
105 *     == general invoker for unary insertArgument combination
106 * (a0:L, a1:L)=>{ t2:L = FilterMethodHandle#filter(a0);
107 *                 t3:L = MethodHandle#invoke(t2, a1);
108 *                 t4:L = FilterMethodHandle#target(a0);
109 *                 t5:L = MethodHandle#invoke(t4, t3); t5 }
110 *     == general invoker for unary filterArgument combination
111 * (a0:L, a1:L)=>{ ...(same as previous example)...
112 *                 t5:L = MethodHandle#invoke(t4, t3, a1); t5 }
113 *     == general invoker for unary/unary foldArgument combination
114 * (a0:L, a1:I)=>{ t2:I = identity(long).asType((int)->long)(a1); t2 }
115 *     == invoker for identity method handle which performs i2l
116 * (a0:L, a1:L)=>{ t2:L = BoundMethodHandle#argument(a0);
117 *                 t3:L = Class#cast(t2,a1); t3 }
118 *     == invoker for identity method handle which performs cast
119 * }</pre></blockquote>
120 * <p>
121 * @author John Rose, JSR 292 EG
122 */
123class LambdaForm {
124    final int arity;
125    final int result;
126    final boolean forceInline;
127    final MethodHandle customized;
128    @Stable final Name[] names;
129    final String debugName;
130    final Kind kind;
131    MemberName vmentry;   // low-level behavior, or null if not yet prepared
132    private boolean isCompiled;
133
134    // Either a LambdaForm cache (managed by LambdaFormEditor) or a link to uncustomized version (for customized LF)
135    volatile Object transformCache;
136
137    public static final int VOID_RESULT = -1, LAST_RESULT = -2;
138
139    enum BasicType {
140        L_TYPE('L', Object.class, Wrapper.OBJECT),  // all reference types
141        I_TYPE('I', int.class,    Wrapper.INT),
142        J_TYPE('J', long.class,   Wrapper.LONG),
143        F_TYPE('F', float.class,  Wrapper.FLOAT),
144        D_TYPE('D', double.class, Wrapper.DOUBLE),  // all primitive types
145        V_TYPE('V', void.class,   Wrapper.VOID);    // not valid in all contexts
146
147        static final BasicType[] ALL_TYPES = BasicType.values();
148        static final BasicType[] ARG_TYPES = Arrays.copyOf(ALL_TYPES, ALL_TYPES.length-1);
149
150        static final int ARG_TYPE_LIMIT = ARG_TYPES.length;
151        static final int TYPE_LIMIT = ALL_TYPES.length;
152
153        final char btChar;
154        final Class<?> btClass;
155        final Wrapper btWrapper;
156
157        private BasicType(char btChar, Class<?> btClass, Wrapper wrapper) {
158            this.btChar = btChar;
159            this.btClass = btClass;
160            this.btWrapper = wrapper;
161        }
162
163        char basicTypeChar() {
164            return btChar;
165        }
166        Class<?> basicTypeClass() {
167            return btClass;
168        }
169        Wrapper basicTypeWrapper() {
170            return btWrapper;
171        }
172        int basicTypeSlots() {
173            return btWrapper.stackSlots();
174        }
175
176        static BasicType basicType(byte type) {
177            return ALL_TYPES[type];
178        }
179        static BasicType basicType(char type) {
180            switch (type) {
181                case 'L': return L_TYPE;
182                case 'I': return I_TYPE;
183                case 'J': return J_TYPE;
184                case 'F': return F_TYPE;
185                case 'D': return D_TYPE;
186                case 'V': return V_TYPE;
187                // all subword types are represented as ints
188                case 'Z':
189                case 'B':
190                case 'S':
191                case 'C':
192                    return I_TYPE;
193                default:
194                    throw newInternalError("Unknown type char: '"+type+"'");
195            }
196        }
197        static BasicType basicType(Wrapper type) {
198            char c = type.basicTypeChar();
199            return basicType(c);
200        }
201        static BasicType basicType(Class<?> type) {
202            if (!type.isPrimitive())  return L_TYPE;
203            return basicType(Wrapper.forPrimitiveType(type));
204        }
205        static BasicType[] basicTypes(String types) {
206            BasicType[] btypes = new BasicType[types.length()];
207            for (int i = 0; i < btypes.length; i++) {
208                btypes[i] = basicType(types.charAt(i));
209            }
210            return btypes;
211        }
212        static String basicTypeDesc(BasicType[] types) {
213            if (types == null) {
214                return null;
215            }
216            if (types.length == 0) {
217                return "";
218            }
219            StringBuilder sb = new StringBuilder();
220            for (BasicType bt : types) {
221                sb.append(bt.basicTypeChar());
222            }
223            return sb.toString();
224        }
225        static int[] basicTypeOrds(BasicType[] types) {
226            if (types == null) {
227                return null;
228            }
229            int[] a = new int[types.length];
230            for(int i = 0; i < types.length; ++i) {
231                a[i] = types[i].ordinal();
232            }
233            return a;
234        }
235
236        static char basicTypeChar(Class<?> type) {
237            return basicType(type).btChar;
238        }
239
240        static byte[] basicTypesOrd(Class<?>[] types) {
241            byte[] ords = new byte[types.length];
242            for (int i = 0; i < ords.length; i++) {
243                ords[i] = (byte)basicType(types[i]).ordinal();
244            }
245            return ords;
246        }
247
248        static boolean isBasicTypeChar(char c) {
249            return "LIJFDV".indexOf(c) >= 0;
250        }
251        static boolean isArgBasicTypeChar(char c) {
252            return "LIJFD".indexOf(c) >= 0;
253        }
254
255        static { assert(checkBasicType()); }
256        private static boolean checkBasicType() {
257            for (int i = 0; i < ARG_TYPE_LIMIT; i++) {
258                assert ARG_TYPES[i].ordinal() == i;
259                assert ARG_TYPES[i] == ALL_TYPES[i];
260            }
261            for (int i = 0; i < TYPE_LIMIT; i++) {
262                assert ALL_TYPES[i].ordinal() == i;
263            }
264            assert ALL_TYPES[TYPE_LIMIT - 1] == V_TYPE;
265            assert !Arrays.asList(ARG_TYPES).contains(V_TYPE);
266            return true;
267        }
268    }
269
270    enum Kind {
271        GENERIC(""),
272        ZERO("zero"),
273        IDENTITY("identity"),
274        BOUND_REINVOKER("BMH.reinvoke"),
275        REINVOKER("MH.reinvoke"),
276        DELEGATE("MH.delegate"),
277        EXACT_LINKER("MH.invokeExact_MT"),
278        EXACT_INVOKER("MH.exactInvoker"),
279        GENERIC_LINKER("MH.invoke_MT"),
280        GENERIC_INVOKER("MH.invoker"),
281        DIRECT_INVOKE_VIRTUAL("DMH.invokeVirtual"),
282        DIRECT_INVOKE_SPECIAL("DMH.invokeSpecial"),
283        DIRECT_INVOKE_STATIC("DMH.invokeStatic"),
284        DIRECT_NEW_INVOKE_SPECIAL("DMH.newInvokeSpecial"),
285        DIRECT_INVOKE_INTERFACE("DMH.invokeInterface"),
286        DIRECT_INVOKE_STATIC_INIT("DMH.invokeStaticInit"),
287        GET_OBJECT("getObject"),
288        PUT_OBJECT("putObject"),
289        GET_OBJECT_VOLATILE("getObjectVolatile"),
290        PUT_OBJECT_VOLATILE("putObjectVolatile"),
291        GET_INT("getInt"),
292        PUT_INT("putInt"),
293        GET_INT_VOLATILE("getIntVolatile"),
294        PUT_INT_VOLATILE("putIntVolatile"),
295        GET_BOOLEAN("getBoolean"),
296        PUT_BOOLEAN("putBoolean"),
297        GET_BOOLEAN_VOLATILE("getBooleanVolatile"),
298        PUT_BOOLEAN_VOLATILE("putBooleanVolatile"),
299        GET_BYTE("getByte"),
300        PUT_BYTE("putByte"),
301        GET_BYTE_VOLATILE("getByteVolatile"),
302        PUT_BYTE_VOLATILE("putByteVolatile"),
303        GET_CHAR("getChar"),
304        PUT_CHAR("putChar"),
305        GET_CHAR_VOLATILE("getCharVolatile"),
306        PUT_CHAR_VOLATILE("putCharVolatile"),
307        GET_SHORT("getShort"),
308        PUT_SHORT("putShort"),
309        GET_SHORT_VOLATILE("getShortVolatile"),
310        PUT_SHORT_VOLATILE("putShortVolatile"),
311        GET_LONG("getLong"),
312        PUT_LONG("putLong"),
313        GET_LONG_VOLATILE("getLongVolatile"),
314        PUT_LONG_VOLATILE("putLongVolatile"),
315        GET_FLOAT("getFloat"),
316        PUT_FLOAT("putFloat"),
317        GET_FLOAT_VOLATILE("getFloatVolatile"),
318        PUT_FLOAT_VOLATILE("putFloatVolatile"),
319        GET_DOUBLE("getDouble"),
320        PUT_DOUBLE("putDouble"),
321        GET_DOUBLE_VOLATILE("getDoubleVolatile"),
322        PUT_DOUBLE_VOLATILE("putDoubleVolatile");
323
324        final String defaultLambdaName;
325        final String methodName;
326
327        private Kind(String defaultLambdaName) {
328            this.defaultLambdaName = defaultLambdaName;
329            int p = defaultLambdaName.indexOf('.');
330            if (p > -1) {
331                this.methodName = defaultLambdaName.substring(p + 1);
332            } else {
333                this.methodName = defaultLambdaName;
334            }
335        }
336    }
337
338    LambdaForm(String debugName,
339               int arity, Name[] names, int result) {
340        this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
341    }
342    LambdaForm(String debugName,
343               int arity, Name[] names, int result, Kind kind) {
344        this(debugName, arity, names, result, /*forceInline=*/true, /*customized=*/null, kind);
345    }
346    LambdaForm(String debugName,
347               int arity, Name[] names, int result, boolean forceInline, MethodHandle customized) {
348        this(debugName, arity, names, result, forceInline, customized, Kind.GENERIC);
349    }
350    LambdaForm(String debugName,
351               int arity, Name[] names, int result, boolean forceInline, MethodHandle customized, Kind kind) {
352        assert(namesOK(arity, names));
353        this.arity = arity;
354        this.result = fixResult(result, names);
355        this.names = names.clone();
356        this.debugName = fixDebugName(debugName);
357        this.forceInline = forceInline;
358        this.customized = customized;
359        this.kind = kind;
360        int maxOutArity = normalize();
361        if (maxOutArity > MethodType.MAX_MH_INVOKER_ARITY) {
362            // Cannot use LF interpreter on very high arity expressions.
363            assert(maxOutArity <= MethodType.MAX_JVM_ARITY);
364            compileToBytecode();
365        }
366    }
367    LambdaForm(String debugName,
368               int arity, Name[] names) {
369        this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, Kind.GENERIC);
370    }
371    LambdaForm(String debugName,
372               int arity, Name[] names, Kind kind) {
373        this(debugName, arity, names, LAST_RESULT, /*forceInline=*/true, /*customized=*/null, kind);
374    }
375    LambdaForm(String debugName,
376               int arity, Name[] names, boolean forceInline) {
377        this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, Kind.GENERIC);
378    }
379    LambdaForm(String debugName,
380               int arity, Name[] names, boolean forceInline, Kind kind) {
381        this(debugName, arity, names, LAST_RESULT, forceInline, /*customized=*/null, kind);
382    }
383    LambdaForm(String debugName,
384               Name[] formals, Name[] temps, Name result) {
385        this(debugName,
386             formals.length, buildNames(formals, temps, result), LAST_RESULT, /*forceInline=*/true, /*customized=*/null);
387    }
388    LambdaForm(String debugName,
389               Name[] formals, Name[] temps, Name result, boolean forceInline) {
390        this(debugName,
391             formals.length, buildNames(formals, temps, result), LAST_RESULT, forceInline, /*customized=*/null);
392    }
393
394    private static Name[] buildNames(Name[] formals, Name[] temps, Name result) {
395        int arity = formals.length;
396        int length = arity + temps.length + (result == null ? 0 : 1);
397        Name[] names = Arrays.copyOf(formals, length);
398        System.arraycopy(temps, 0, names, arity, temps.length);
399        if (result != null)
400            names[length - 1] = result;
401        return names;
402    }
403
404    private LambdaForm(MethodType mt) {
405        // Make a blank lambda form, which returns a constant zero or null.
406        // It is used as a template for managing the invocation of similar forms that are non-empty.
407        // Called only from getPreparedForm.
408        this.arity = mt.parameterCount();
409        this.result = (mt.returnType() == void.class || mt.returnType() == Void.class) ? -1 : arity;
410        this.names = buildEmptyNames(arity, mt, result == -1);
411        this.debugName = "LF.zero";
412        this.forceInline = true;
413        this.customized = null;
414        this.kind = Kind.GENERIC;
415        assert(nameRefsAreLegal());
416        assert(isEmpty());
417        String sig = null;
418        assert(isValidSignature(sig = basicTypeSignature()));
419        assert(sig.equals(basicTypeSignature())) : sig + " != " + basicTypeSignature();
420    }
421
422    private static Name[] buildEmptyNames(int arity, MethodType mt, boolean isVoid) {
423        Name[] names = arguments(isVoid ? 0 : 1, mt);
424        if (!isVoid) {
425            Name zero = new Name(constantZero(basicType(mt.returnType())));
426            names[arity] = zero.newIndex(arity);
427        }
428        return names;
429    }
430
431    private static int fixResult(int result, Name[] names) {
432        if (result == LAST_RESULT)
433            result = names.length - 1;  // might still be void
434        if (result >= 0 && names[result].type == V_TYPE)
435            result = VOID_RESULT;
436        return result;
437    }
438
439    private static String fixDebugName(String debugName) {
440        if (DEBUG_NAME_COUNTERS != null) {
441            int under = debugName.indexOf('_');
442            int length = debugName.length();
443            if (under < 0)  under = length;
444            String debugNameStem = debugName.substring(0, under);
445            Integer ctr;
446            synchronized (DEBUG_NAME_COUNTERS) {
447                ctr = DEBUG_NAME_COUNTERS.get(debugNameStem);
448                if (ctr == null)  ctr = 0;
449                DEBUG_NAME_COUNTERS.put(debugNameStem, ctr+1);
450            }
451            StringBuilder buf = new StringBuilder(debugNameStem);
452            buf.append('_');
453            int leadingZero = buf.length();
454            buf.append((int) ctr);
455            for (int i = buf.length() - leadingZero; i < 3; i++)
456                buf.insert(leadingZero, '0');
457            if (under < length) {
458                ++under;    // skip "_"
459                while (under < length && Character.isDigit(debugName.charAt(under))) {
460                    ++under;
461                }
462                if (under < length && debugName.charAt(under) == '_')  ++under;
463                if (under < length)
464                    buf.append('_').append(debugName, under, length);
465            }
466            return buf.toString();
467        }
468        return debugName;
469    }
470
471    private static boolean namesOK(int arity, Name[] names) {
472        for (int i = 0; i < names.length; i++) {
473            Name n = names[i];
474            assert(n != null) : "n is null";
475            if (i < arity)
476                assert( n.isParam()) : n + " is not param at " + i;
477            else
478                assert(!n.isParam()) : n + " is param at " + i;
479        }
480        return true;
481    }
482
483    /** Customize LambdaForm for a particular MethodHandle */
484    LambdaForm customize(MethodHandle mh) {
485        LambdaForm customForm = new LambdaForm(debugName, arity, names, result, forceInline, mh, kind);
486        if (COMPILE_THRESHOLD >= 0 && isCompiled) {
487            // If shared LambdaForm has been compiled, compile customized version as well.
488            customForm.compileToBytecode();
489        }
490        customForm.transformCache = this; // LambdaFormEditor should always use uncustomized form.
491        return customForm;
492    }
493
494    /** Get uncustomized flavor of the LambdaForm */
495    LambdaForm uncustomize() {
496        if (customized == null) {
497            return this;
498        }
499        assert(transformCache != null); // Customized LambdaForm should always has a link to uncustomized version.
500        LambdaForm uncustomizedForm = (LambdaForm)transformCache;
501        if (COMPILE_THRESHOLD >= 0 && isCompiled) {
502            // If customized LambdaForm has been compiled, compile uncustomized version as well.
503            uncustomizedForm.compileToBytecode();
504        }
505        return uncustomizedForm;
506    }
507
508    /** Renumber and/or replace params so that they are interned and canonically numbered.
509     *  @return maximum argument list length among the names (since we have to pass over them anyway)
510     */
511    private int normalize() {
512        Name[] oldNames = null;
513        int maxOutArity = 0;
514        int changesStart = 0;
515        for (int i = 0; i < names.length; i++) {
516            Name n = names[i];
517            if (!n.initIndex(i)) {
518                if (oldNames == null) {
519                    oldNames = names.clone();
520                    changesStart = i;
521                }
522                names[i] = n.cloneWithIndex(i);
523            }
524            if (n.arguments != null && maxOutArity < n.arguments.length)
525                maxOutArity = n.arguments.length;
526        }
527        if (oldNames != null) {
528            int startFixing = arity;
529            if (startFixing <= changesStart)
530                startFixing = changesStart+1;
531            for (int i = startFixing; i < names.length; i++) {
532                Name fixed = names[i].replaceNames(oldNames, names, changesStart, i);
533                names[i] = fixed.newIndex(i);
534            }
535        }
536        assert(nameRefsAreLegal());
537        int maxInterned = Math.min(arity, INTERNED_ARGUMENT_LIMIT);
538        boolean needIntern = false;
539        for (int i = 0; i < maxInterned; i++) {
540            Name n = names[i], n2 = internArgument(n);
541            if (n != n2) {
542                names[i] = n2;
543                needIntern = true;
544            }
545        }
546        if (needIntern) {
547            for (int i = arity; i < names.length; i++) {
548                names[i].internArguments();
549            }
550        }
551        assert(nameRefsAreLegal());
552        return maxOutArity;
553    }
554
555    /**
556     * Check that all embedded Name references are localizable to this lambda,
557     * and are properly ordered after their corresponding definitions.
558     * <p>
559     * Note that a Name can be local to multiple lambdas, as long as
560     * it possesses the same index in each use site.
561     * This allows Name references to be freely reused to construct
562     * fresh lambdas, without confusion.
563     */
564    boolean nameRefsAreLegal() {
565        assert(arity >= 0 && arity <= names.length);
566        assert(result >= -1 && result < names.length);
567        // Do all names possess an index consistent with their local definition order?
568        for (int i = 0; i < arity; i++) {
569            Name n = names[i];
570            assert(n.index() == i) : Arrays.asList(n.index(), i);
571            assert(n.isParam());
572        }
573        // Also, do all local name references
574        for (int i = arity; i < names.length; i++) {
575            Name n = names[i];
576            assert(n.index() == i);
577            for (Object arg : n.arguments) {
578                if (arg instanceof Name) {
579                    Name n2 = (Name) arg;
580                    int i2 = n2.index;
581                    assert(0 <= i2 && i2 < names.length) : n.debugString() + ": 0 <= i2 && i2 < names.length: 0 <= " + i2 + " < " + names.length;
582                    assert(names[i2] == n2) : Arrays.asList("-1-", i, "-2-", n.debugString(), "-3-", i2, "-4-", n2.debugString(), "-5-", names[i2].debugString(), "-6-", this);
583                    assert(i2 < i);  // ref must come after def!
584                }
585            }
586        }
587        return true;
588    }
589
590    /** Invoke this form on the given arguments. */
591    // final Object invoke(Object... args) throws Throwable {
592    //     // NYI: fit this into the fast path?
593    //     return interpretWithArguments(args);
594    // }
595
596    /** Report the return type. */
597    BasicType returnType() {
598        if (result < 0)  return V_TYPE;
599        Name n = names[result];
600        return n.type;
601    }
602
603    /** Report the N-th argument type. */
604    BasicType parameterType(int n) {
605        return parameter(n).type;
606    }
607
608    /** Report the N-th argument name. */
609    Name parameter(int n) {
610        assert(n < arity);
611        Name param = names[n];
612        assert(param.isParam());
613        return param;
614    }
615
616    /** Report the N-th argument type constraint. */
617    Object parameterConstraint(int n) {
618        return parameter(n).constraint;
619    }
620
621    /** Report the arity. */
622    int arity() {
623        return arity;
624    }
625
626    /** Report the number of expressions (non-parameter names). */
627    int expressionCount() {
628        return names.length - arity;
629    }
630
631    /** Return the method type corresponding to my basic type signature. */
632    MethodType methodType() {
633        Class<?>[] ptypes = new Class<?>[arity];
634        for (int i = 0; i < arity; ++i) {
635            ptypes[i] = parameterType(i).btClass;
636        }
637        return MethodType.methodType(returnType().btClass, ptypes);
638    }
639
640    /** Return ABC_Z, where the ABC are parameter type characters, and Z is the return type character. */
641    final String basicTypeSignature() {
642        StringBuilder buf = new StringBuilder(arity() + 3);
643        for (int i = 0, a = arity(); i < a; i++)
644            buf.append(parameterType(i).basicTypeChar());
645        return buf.append('_').append(returnType().basicTypeChar()).toString();
646    }
647    static int signatureArity(String sig) {
648        assert(isValidSignature(sig));
649        return sig.indexOf('_');
650    }
651    static BasicType signatureReturn(String sig) {
652        return basicType(sig.charAt(signatureArity(sig) + 1));
653    }
654    static boolean isValidSignature(String sig) {
655        int arity = sig.indexOf('_');
656        if (arity < 0)  return false;  // must be of the form *_*
657        int siglen = sig.length();
658        if (siglen != arity + 2)  return false;  // *_X
659        for (int i = 0; i < siglen; i++) {
660            if (i == arity)  continue;  // skip '_'
661            char c = sig.charAt(i);
662            if (c == 'V')
663                return (i == siglen - 1 && arity == siglen - 2);
664            if (!isArgBasicTypeChar(c))  return false; // must be [LIJFD]
665        }
666        return true;  // [LIJFD]*_[LIJFDV]
667    }
668    static MethodType signatureType(String sig) {
669        Class<?>[] ptypes = new Class<?>[signatureArity(sig)];
670        for (int i = 0; i < ptypes.length; i++)
671            ptypes[i] = basicType(sig.charAt(i)).btClass;
672        Class<?> rtype = signatureReturn(sig).btClass;
673        return MethodType.methodType(rtype, ptypes);
674    }
675
676    /**
677     * Check if i-th name is a call to MethodHandleImpl.selectAlternative.
678     */
679    boolean isSelectAlternative(int pos) {
680        // selectAlternative idiom:
681        //   t_{n}:L=MethodHandleImpl.selectAlternative(...)
682        //   t_{n+1}:?=MethodHandle.invokeBasic(t_{n}, ...)
683        if (pos+1 >= names.length)  return false;
684        Name name0 = names[pos];
685        Name name1 = names[pos+1];
686        return name0.refersTo(MethodHandleImpl.class, "selectAlternative") &&
687                name1.isInvokeBasic() &&
688                name1.lastUseIndex(name0) == 0 && // t_{n+1}:?=MethodHandle.invokeBasic(t_{n}, ...)
689                lastUseIndex(name0) == pos+1;     // t_{n} is local: used only in t_{n+1}
690    }
691
692    private boolean isMatchingIdiom(int pos, String idiomName, int nArgs) {
693        if (pos+2 >= names.length)  return false;
694        Name name0 = names[pos];
695        Name name1 = names[pos+1];
696        Name name2 = names[pos+2];
697        return name1.refersTo(MethodHandleImpl.class, idiomName) &&
698                name0.isInvokeBasic() &&
699                name2.isInvokeBasic() &&
700                name1.lastUseIndex(name0) == nArgs && // t_{n+1}:L=MethodHandleImpl.<invoker>(<args>, t_{n});
701                lastUseIndex(name0) == pos+1 &&       // t_{n} is local: used only in t_{n+1}
702                name2.lastUseIndex(name1) == 1 &&     // t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1})
703                lastUseIndex(name1) == pos+2;         // t_{n+1} is local: used only in t_{n+2}
704    }
705
706    /**
707     * Check if i-th name is a start of GuardWithCatch idiom.
708     */
709    boolean isGuardWithCatch(int pos) {
710        // GuardWithCatch idiom:
711        //   t_{n}:L=MethodHandle.invokeBasic(...)
712        //   t_{n+1}:L=MethodHandleImpl.guardWithCatch(*, *, *, t_{n});
713        //   t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1})
714        return isMatchingIdiom(pos, "guardWithCatch", 3);
715    }
716
717    /**
718     * Check if i-th name is a start of the tryFinally idiom.
719     */
720    boolean isTryFinally(int pos) {
721        // tryFinally idiom:
722        //   t_{n}:L=MethodHandle.invokeBasic(...)
723        //   t_{n+1}:L=MethodHandleImpl.tryFinally(*, *, t_{n})
724        //   t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1})
725        return isMatchingIdiom(pos, "tryFinally", 2);
726    }
727
728    /**
729     * Check if i-th name is a start of the loop idiom.
730     */
731    boolean isLoop(int pos) {
732        // loop idiom:
733        //   t_{n}:L=MethodHandle.invokeBasic(...)
734        //   t_{n+1}:L=MethodHandleImpl.loop(types, *, t_{n})
735        //   t_{n+2}:?=MethodHandle.invokeBasic(*, t_{n+1})
736        return isMatchingIdiom(pos, "loop", 2);
737    }
738
739    /*
740     * Code generation issues:
741     *
742     * Compiled LFs should be reusable in general.
743     * The biggest issue is how to decide when to pull a name into
744     * the bytecode, versus loading a reified form from the MH data.
745     *
746     * For example, an asType wrapper may require execution of a cast
747     * after a call to a MH.  The target type of the cast can be placed
748     * as a constant in the LF itself.  This will force the cast type
749     * to be compiled into the bytecodes and native code for the MH.
750     * Or, the target type of the cast can be erased in the LF, and
751     * loaded from the MH data.  (Later on, if the MH as a whole is
752     * inlined, the data will flow into the inlined instance of the LF,
753     * as a constant, and the end result will be an optimal cast.)
754     *
755     * This erasure of cast types can be done with any use of
756     * reference types.  It can also be done with whole method
757     * handles.  Erasing a method handle might leave behind
758     * LF code that executes correctly for any MH of a given
759     * type, and load the required MH from the enclosing MH's data.
760     * Or, the erasure might even erase the expected MT.
761     *
762     * Also, for direct MHs, the MemberName of the target
763     * could be erased, and loaded from the containing direct MH.
764     * As a simple case, a LF for all int-valued non-static
765     * field getters would perform a cast on its input argument
766     * (to non-constant base type derived from the MemberName)
767     * and load an integer value from the input object
768     * (at a non-constant offset also derived from the MemberName).
769     * Such MN-erased LFs would be inlinable back to optimized
770     * code, whenever a constant enclosing DMH is available
771     * to supply a constant MN from its data.
772     *
773     * The main problem here is to keep LFs reasonably generic,
774     * while ensuring that hot spots will inline good instances.
775     * "Reasonably generic" means that we don't end up with
776     * repeated versions of bytecode or machine code that do
777     * not differ in their optimized form.  Repeated versions
778     * of machine would have the undesirable overheads of
779     * (a) redundant compilation work and (b) extra I$ pressure.
780     * To control repeated versions, we need to be ready to
781     * erase details from LFs and move them into MH data,
782     * whevener those details are not relevant to significant
783     * optimization.  "Significant" means optimization of
784     * code that is actually hot.
785     *
786     * Achieving this may require dynamic splitting of MHs, by replacing
787     * a generic LF with a more specialized one, on the same MH,
788     * if (a) the MH is frequently executed and (b) the MH cannot
789     * be inlined into a containing caller, such as an invokedynamic.
790     *
791     * Compiled LFs that are no longer used should be GC-able.
792     * If they contain non-BCP references, they should be properly
793     * interlinked with the class loader(s) that their embedded types
794     * depend on.  This probably means that reusable compiled LFs
795     * will be tabulated (indexed) on relevant class loaders,
796     * or else that the tables that cache them will have weak links.
797     */
798
799    /**
800     * Make this LF directly executable, as part of a MethodHandle.
801     * Invariant:  Every MH which is invoked must prepare its LF
802     * before invocation.
803     * (In principle, the JVM could do this very lazily,
804     * as a sort of pre-invocation linkage step.)
805     */
806    public void prepare() {
807        if (COMPILE_THRESHOLD == 0 && !forceInterpretation() && !isCompiled) {
808            compileToBytecode();
809        }
810        if (this.vmentry != null) {
811            // already prepared (e.g., a primitive DMH invoker form)
812            return;
813        }
814        MethodType mtype = methodType();
815        LambdaForm prep = mtype.form().cachedLambdaForm(MethodTypeForm.LF_INTERPRET);
816        if (prep == null) {
817            assert (isValidSignature(basicTypeSignature()));
818            prep = new LambdaForm(mtype);
819            prep.vmentry = InvokerBytecodeGenerator.generateLambdaFormInterpreterEntryPoint(mtype);
820            prep = mtype.form().setCachedLambdaForm(MethodTypeForm.LF_INTERPRET, prep);
821        }
822        this.vmentry = prep.vmentry;
823        // TO DO: Maybe add invokeGeneric, invokeWithArguments
824    }
825
826    private static @Stable PerfCounter LF_FAILED;
827
828    private static PerfCounter failedCompilationCounter() {
829        if (LF_FAILED == null) {
830            LF_FAILED = PerfCounter.newPerfCounter("java.lang.invoke.failedLambdaFormCompilations");
831        }
832        return LF_FAILED;
833    }
834
835    /** Generate optimizable bytecode for this form. */
836    void compileToBytecode() {
837        if (forceInterpretation()) {
838            return; // this should not be compiled
839        }
840        if (vmentry != null && isCompiled) {
841            return;  // already compiled somehow
842        }
843        MethodType invokerType = methodType();
844        assert(vmentry == null || vmentry.getMethodType().basicType().equals(invokerType));
845        try {
846            vmentry = InvokerBytecodeGenerator.generateCustomizedCode(this, invokerType);
847            if (TRACE_INTERPRETER)
848                traceInterpreter("compileToBytecode", this);
849            isCompiled = true;
850        } catch (InvokerBytecodeGenerator.BytecodeGenerationException bge) {
851            // bytecode generation failed - mark this LambdaForm as to be run in interpretation mode only
852            invocationCounter = -1;
853            failedCompilationCounter().increment();
854            if (LOG_LF_COMPILATION_FAILURE) {
855                System.out.println("LambdaForm compilation failed: " + this);
856                bge.printStackTrace(System.out);
857            }
858        } catch (Error e) {
859            // Pass through any error
860            throw e;
861        } catch (Exception e) {
862            // Wrap any exception
863            throw newInternalError(this.toString(), e);
864        }
865    }
866
867    // The next few routines are called only from assert expressions
868    // They verify that the built-in invokers process the correct raw data types.
869    private static boolean argumentTypesMatch(String sig, Object[] av) {
870        int arity = signatureArity(sig);
871        assert(av.length == arity) : "av.length == arity: av.length=" + av.length + ", arity=" + arity;
872        assert(av[0] instanceof MethodHandle) : "av[0] not instace of MethodHandle: " + av[0];
873        MethodHandle mh = (MethodHandle) av[0];
874        MethodType mt = mh.type();
875        assert(mt.parameterCount() == arity-1);
876        for (int i = 0; i < av.length; i++) {
877            Class<?> pt = (i == 0 ? MethodHandle.class : mt.parameterType(i-1));
878            assert(valueMatches(basicType(sig.charAt(i)), pt, av[i]));
879        }
880        return true;
881    }
882    private static boolean valueMatches(BasicType tc, Class<?> type, Object x) {
883        // The following line is needed because (...)void method handles can use non-void invokers
884        if (type == void.class)  tc = V_TYPE;   // can drop any kind of value
885        assert tc == basicType(type) : tc + " == basicType(" + type + ")=" + basicType(type);
886        switch (tc) {
887        case I_TYPE: assert checkInt(type, x)   : "checkInt(" + type + "," + x +")";   break;
888        case J_TYPE: assert x instanceof Long   : "instanceof Long: " + x;             break;
889        case F_TYPE: assert x instanceof Float  : "instanceof Float: " + x;            break;
890        case D_TYPE: assert x instanceof Double : "instanceof Double: " + x;           break;
891        case L_TYPE: assert checkRef(type, x)   : "checkRef(" + type + "," + x + ")";  break;
892        case V_TYPE: break;  // allow anything here; will be dropped
893        default:  assert(false);
894        }
895        return true;
896    }
897    private static boolean returnTypesMatch(String sig, Object[] av, Object res) {
898        MethodHandle mh = (MethodHandle) av[0];
899        return valueMatches(signatureReturn(sig), mh.type().returnType(), res);
900    }
901    private static boolean checkInt(Class<?> type, Object x) {
902        assert(x instanceof Integer);
903        if (type == int.class)  return true;
904        Wrapper w = Wrapper.forBasicType(type);
905        assert(w.isSubwordOrInt());
906        Object x1 = Wrapper.INT.wrap(w.wrap(x));
907        return x.equals(x1);
908    }
909    private static boolean checkRef(Class<?> type, Object x) {
910        assert(!type.isPrimitive());
911        if (x == null)  return true;
912        if (type.isInterface())  return true;
913        return type.isInstance(x);
914    }
915
916    /** If the invocation count hits the threshold we spin bytecodes and call that subsequently. */
917    private static final int COMPILE_THRESHOLD;
918    static {
919        COMPILE_THRESHOLD = Math.max(-1, MethodHandleStatics.COMPILE_THRESHOLD);
920    }
921    private int invocationCounter = 0; // a value of -1 indicates LambdaForm interpretation mode forever
922
923    private boolean forceInterpretation() {
924        return invocationCounter == -1;
925    }
926
927    @Hidden
928    @DontInline
929    /** Interpretively invoke this form on the given arguments. */
930    Object interpretWithArguments(Object... argumentValues) throws Throwable {
931        if (TRACE_INTERPRETER)
932            return interpretWithArgumentsTracing(argumentValues);
933        checkInvocationCounter();
934        assert(arityCheck(argumentValues));
935        Object[] values = Arrays.copyOf(argumentValues, names.length);
936        for (int i = argumentValues.length; i < values.length; i++) {
937            values[i] = interpretName(names[i], values);
938        }
939        Object rv = (result < 0) ? null : values[result];
940        assert(resultCheck(argumentValues, rv));
941        return rv;
942    }
943
944    @Hidden
945    @DontInline
946    /** Evaluate a single Name within this form, applying its function to its arguments. */
947    Object interpretName(Name name, Object[] values) throws Throwable {
948        if (TRACE_INTERPRETER)
949            traceInterpreter("| interpretName", name.debugString(), (Object[]) null);
950        Object[] arguments = Arrays.copyOf(name.arguments, name.arguments.length, Object[].class);
951        for (int i = 0; i < arguments.length; i++) {
952            Object a = arguments[i];
953            if (a instanceof Name) {
954                int i2 = ((Name)a).index();
955                assert(names[i2] == a);
956                a = values[i2];
957                arguments[i] = a;
958            }
959        }
960        return name.function.invokeWithArguments(arguments);
961    }
962
963    private void checkInvocationCounter() {
964        if (COMPILE_THRESHOLD != 0 &&
965            !forceInterpretation() && invocationCounter < COMPILE_THRESHOLD) {
966            invocationCounter++;  // benign race
967            if (invocationCounter >= COMPILE_THRESHOLD) {
968                // Replace vmentry with a bytecode version of this LF.
969                compileToBytecode();
970            }
971        }
972    }
973    Object interpretWithArgumentsTracing(Object... argumentValues) throws Throwable {
974        traceInterpreter("[ interpretWithArguments", this, argumentValues);
975        if (!forceInterpretation() && invocationCounter < COMPILE_THRESHOLD) {
976            int ctr = invocationCounter++;  // benign race
977            traceInterpreter("| invocationCounter", ctr);
978            if (invocationCounter >= COMPILE_THRESHOLD) {
979                compileToBytecode();
980            }
981        }
982        Object rval;
983        try {
984            assert(arityCheck(argumentValues));
985            Object[] values = Arrays.copyOf(argumentValues, names.length);
986            for (int i = argumentValues.length; i < values.length; i++) {
987                values[i] = interpretName(names[i], values);
988            }
989            rval = (result < 0) ? null : values[result];
990        } catch (Throwable ex) {
991            traceInterpreter("] throw =>", ex);
992            throw ex;
993        }
994        traceInterpreter("] return =>", rval);
995        return rval;
996    }
997
998    static void traceInterpreter(String event, Object obj, Object... args) {
999        if (TRACE_INTERPRETER) {
1000            System.out.println("LFI: "+event+" "+(obj != null ? obj : "")+(args != null && args.length != 0 ? Arrays.asList(args) : ""));
1001        }
1002    }
1003    static void traceInterpreter(String event, Object obj) {
1004        traceInterpreter(event, obj, (Object[])null);
1005    }
1006    private boolean arityCheck(Object[] argumentValues) {
1007        assert(argumentValues.length == arity) : arity+"!="+Arrays.asList(argumentValues)+".length";
1008        // also check that the leading (receiver) argument is somehow bound to this LF:
1009        assert(argumentValues[0] instanceof MethodHandle) : "not MH: " + argumentValues[0];
1010        MethodHandle mh = (MethodHandle) argumentValues[0];
1011        assert(mh.internalForm() == this);
1012        // note:  argument #0 could also be an interface wrapper, in the future
1013        argumentTypesMatch(basicTypeSignature(), argumentValues);
1014        return true;
1015    }
1016    private boolean resultCheck(Object[] argumentValues, Object result) {
1017        MethodHandle mh = (MethodHandle) argumentValues[0];
1018        MethodType mt = mh.type();
1019        assert(valueMatches(returnType(), mt.returnType(), result));
1020        return true;
1021    }
1022
1023    private boolean isEmpty() {
1024        if (result < 0)
1025            return (names.length == arity);
1026        else if (result == arity && names.length == arity + 1)
1027            return names[arity].isConstantZero();
1028        else
1029            return false;
1030    }
1031
1032    public String toString() {
1033        StringBuilder buf = new StringBuilder(debugName+"=Lambda(");
1034        for (int i = 0; i < names.length; i++) {
1035            if (i == arity)  buf.append(")=>{");
1036            Name n = names[i];
1037            if (i >= arity)  buf.append("\n    ");
1038            buf.append(n.paramString());
1039            if (i < arity) {
1040                if (i+1 < arity)  buf.append(",");
1041                continue;
1042            }
1043            buf.append("=").append(n.exprString());
1044            buf.append(";");
1045        }
1046        if (arity == names.length)  buf.append(")=>{");
1047        buf.append(result < 0 ? "void" : names[result]).append("}");
1048        if (TRACE_INTERPRETER) {
1049            // Extra verbosity:
1050            buf.append(":").append(basicTypeSignature());
1051            buf.append("/").append(vmentry);
1052        }
1053        return buf.toString();
1054    }
1055
1056    @Override
1057    public boolean equals(Object obj) {
1058        return obj instanceof LambdaForm && equals((LambdaForm)obj);
1059    }
1060    public boolean equals(LambdaForm that) {
1061        if (this.result != that.result)  return false;
1062        return Arrays.equals(this.names, that.names);
1063    }
1064    public int hashCode() {
1065        return result + 31 * Arrays.hashCode(names);
1066    }
1067    LambdaFormEditor editor() {
1068        return LambdaFormEditor.lambdaFormEditor(this);
1069    }
1070
1071    boolean contains(Name name) {
1072        int pos = name.index();
1073        if (pos >= 0) {
1074            return pos < names.length && name.equals(names[pos]);
1075        }
1076        for (int i = arity; i < names.length; i++) {
1077            if (name.equals(names[i]))
1078                return true;
1079        }
1080        return false;
1081    }
1082
1083    static class NamedFunction {
1084        final MemberName member;
1085        private @Stable MethodHandle resolvedHandle;
1086        @Stable MethodHandle invoker;
1087
1088        NamedFunction(MethodHandle resolvedHandle) {
1089            this(resolvedHandle.internalMemberName(), resolvedHandle);
1090        }
1091        NamedFunction(MemberName member, MethodHandle resolvedHandle) {
1092            this.member = member;
1093            this.resolvedHandle = resolvedHandle;
1094             // The following assert is almost always correct, but will fail for corner cases, such as PrivateInvokeTest.
1095             //assert(!isInvokeBasic(member));
1096        }
1097        NamedFunction(MethodType basicInvokerType) {
1098            assert(basicInvokerType == basicInvokerType.basicType()) : basicInvokerType;
1099            if (basicInvokerType.parameterSlotCount() < MethodType.MAX_MH_INVOKER_ARITY) {
1100                this.resolvedHandle = basicInvokerType.invokers().basicInvoker();
1101                this.member = resolvedHandle.internalMemberName();
1102            } else {
1103                // necessary to pass BigArityTest
1104                this.member = Invokers.invokeBasicMethod(basicInvokerType);
1105            }
1106            assert(isInvokeBasic(member));
1107        }
1108
1109        private static boolean isInvokeBasic(MemberName member) {
1110            return member != null &&
1111                   member.getDeclaringClass() == MethodHandle.class &&
1112                  "invokeBasic".equals(member.getName());
1113        }
1114
1115        // The next 2 constructors are used to break circular dependencies on MH.invokeStatic, etc.
1116        // Any LambdaForm containing such a member is not interpretable.
1117        // This is OK, since all such LFs are prepared with special primitive vmentry points.
1118        // And even without the resolvedHandle, the name can still be compiled and optimized.
1119        NamedFunction(Method method) {
1120            this(new MemberName(method));
1121        }
1122        NamedFunction(MemberName member) {
1123            this(member, null);
1124        }
1125
1126        MethodHandle resolvedHandle() {
1127            if (resolvedHandle == null)  resolve();
1128            return resolvedHandle;
1129        }
1130
1131        synchronized void resolve() {
1132            if (resolvedHandle == null) {
1133                resolvedHandle = DirectMethodHandle.make(member);
1134            }
1135        }
1136
1137        @Override
1138        public boolean equals(Object other) {
1139            if (this == other) return true;
1140            if (other == null) return false;
1141            if (!(other instanceof NamedFunction)) return false;
1142            NamedFunction that = (NamedFunction) other;
1143            return this.member != null && this.member.equals(that.member);
1144        }
1145
1146        @Override
1147        public int hashCode() {
1148            if (member != null)
1149                return member.hashCode();
1150            return super.hashCode();
1151        }
1152
1153        static final MethodType INVOKER_METHOD_TYPE =
1154            MethodType.methodType(Object.class, MethodHandle.class, Object[].class);
1155
1156        private static MethodHandle computeInvoker(MethodTypeForm typeForm) {
1157            typeForm = typeForm.basicType().form();  // normalize to basic type
1158            MethodHandle mh = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1159            if (mh != null)  return mh;
1160            MemberName invoker = InvokerBytecodeGenerator.generateNamedFunctionInvoker(typeForm);  // this could take a while
1161            mh = DirectMethodHandle.make(invoker);
1162            MethodHandle mh2 = typeForm.cachedMethodHandle(MethodTypeForm.MH_NF_INV);
1163            if (mh2 != null)  return mh2;  // benign race
1164            if (!mh.type().equals(INVOKER_METHOD_TYPE))
1165                throw newInternalError(mh.debugString());
1166            return typeForm.setCachedMethodHandle(MethodTypeForm.MH_NF_INV, mh);
1167        }
1168
1169        @Hidden
1170        Object invokeWithArguments(Object... arguments) throws Throwable {
1171            // If we have a cached invoker, call it right away.
1172            // NOTE: The invoker always returns a reference value.
1173            if (TRACE_INTERPRETER)  return invokeWithArgumentsTracing(arguments);
1174            assert(checkArgumentTypes(arguments, methodType()));
1175            return invoker().invokeBasic(resolvedHandle(), arguments);
1176        }
1177
1178        @Hidden
1179        Object invokeWithArgumentsTracing(Object[] arguments) throws Throwable {
1180            Object rval;
1181            try {
1182                traceInterpreter("[ call", this, arguments);
1183                if (invoker == null) {
1184                    traceInterpreter("| getInvoker", this);
1185                    invoker();
1186                }
1187                // resolvedHandle might be uninitialized, ok for tracing
1188                if (resolvedHandle == null) {
1189                    traceInterpreter("| resolve", this);
1190                    resolvedHandle();
1191                }
1192                assert(checkArgumentTypes(arguments, methodType()));
1193                rval = invoker().invokeBasic(resolvedHandle(), arguments);
1194            } catch (Throwable ex) {
1195                traceInterpreter("] throw =>", ex);
1196                throw ex;
1197            }
1198            traceInterpreter("] return =>", rval);
1199            return rval;
1200        }
1201
1202        private MethodHandle invoker() {
1203            if (invoker != null)  return invoker;
1204            // Get an invoker and cache it.
1205            return invoker = computeInvoker(methodType().form());
1206        }
1207
1208        private static boolean checkArgumentTypes(Object[] arguments, MethodType methodType) {
1209            if (true)  return true;  // FIXME
1210            MethodType dstType = methodType.form().erasedType();
1211            MethodType srcType = dstType.basicType().wrap();
1212            Class<?>[] ptypes = new Class<?>[arguments.length];
1213            for (int i = 0; i < arguments.length; i++) {
1214                Object arg = arguments[i];
1215                Class<?> ptype = arg == null ? Object.class : arg.getClass();
1216                // If the dest. type is a primitive we keep the
1217                // argument type.
1218                ptypes[i] = dstType.parameterType(i).isPrimitive() ? ptype : Object.class;
1219            }
1220            MethodType argType = MethodType.methodType(srcType.returnType(), ptypes).wrap();
1221            assert(argType.isConvertibleTo(srcType)) : "wrong argument types: cannot convert " + argType + " to " + srcType;
1222            return true;
1223        }
1224
1225        MethodType methodType() {
1226            if (resolvedHandle != null)
1227                return resolvedHandle.type();
1228            else
1229                // only for certain internal LFs during bootstrapping
1230                return member.getInvocationType();
1231        }
1232
1233        MemberName member() {
1234            assert(assertMemberIsConsistent());
1235            return member;
1236        }
1237
1238        // Called only from assert.
1239        private boolean assertMemberIsConsistent() {
1240            if (resolvedHandle instanceof DirectMethodHandle) {
1241                MemberName m = resolvedHandle.internalMemberName();
1242                assert(m.equals(member));
1243            }
1244            return true;
1245        }
1246
1247        Class<?> memberDeclaringClassOrNull() {
1248            return (member == null) ? null : member.getDeclaringClass();
1249        }
1250
1251        BasicType returnType() {
1252            return basicType(methodType().returnType());
1253        }
1254
1255        BasicType parameterType(int n) {
1256            return basicType(methodType().parameterType(n));
1257        }
1258
1259        int arity() {
1260            return methodType().parameterCount();
1261        }
1262
1263        public String toString() {
1264            if (member == null)  return String.valueOf(resolvedHandle);
1265            return member.getDeclaringClass().getSimpleName()+"."+member.getName();
1266        }
1267
1268        public boolean isIdentity() {
1269            return this.equals(identity(returnType()));
1270        }
1271
1272        public boolean isConstantZero() {
1273            return this.equals(constantZero(returnType()));
1274        }
1275
1276        public MethodHandleImpl.Intrinsic intrinsicName() {
1277            return resolvedHandle == null ? MethodHandleImpl.Intrinsic.NONE
1278                                          : resolvedHandle.intrinsicName();
1279        }
1280    }
1281
1282    public static String basicTypeSignature(MethodType type) {
1283        int params = type.parameterCount();
1284        char[] sig = new char[params + 2];
1285        int sigp = 0;
1286        while (sigp < params) {
1287            sig[sigp] = basicTypeChar(type.parameterType(sigp++));
1288        }
1289        sig[sigp++] = '_';
1290        sig[sigp++] = basicTypeChar(type.returnType());
1291        assert(sigp == sig.length);
1292        return String.valueOf(sig);
1293    }
1294    public static String shortenSignature(String signature) {
1295        // Hack to make signatures more readable when they show up in method names.
1296        final int NO_CHAR = -1, MIN_RUN = 3;
1297        int c0, c1 = NO_CHAR, c1reps = 0;
1298        StringBuilder buf = null;
1299        int len = signature.length();
1300        if (len < MIN_RUN)  return signature;
1301        for (int i = 0; i <= len; i++) {
1302            // shift in the next char:
1303            c0 = c1; c1 = (i == len ? NO_CHAR : signature.charAt(i));
1304            if (c1 == c0) { ++c1reps; continue; }
1305            // shift in the next count:
1306            int c0reps = c1reps; c1reps = 1;
1307            // end of a  character run
1308            if (c0reps < MIN_RUN) {
1309                if (buf != null) {
1310                    while (--c0reps >= 0)
1311                        buf.append((char)c0);
1312                }
1313                continue;
1314            }
1315            // found three or more in a row
1316            if (buf == null)
1317                buf = new StringBuilder().append(signature, 0, i - c0reps);
1318            buf.append((char)c0).append(c0reps);
1319        }
1320        return (buf == null) ? signature : buf.toString();
1321    }
1322
1323    static final class Name {
1324        final BasicType type;
1325        @Stable short index;
1326        final NamedFunction function;
1327        final Object constraint;  // additional type information, if not null
1328        @Stable final Object[] arguments;
1329
1330        private Name(int index, BasicType type, NamedFunction function, Object[] arguments) {
1331            this.index = (short)index;
1332            this.type = type;
1333            this.function = function;
1334            this.arguments = arguments;
1335            this.constraint = null;
1336            assert(this.index == index);
1337        }
1338        private Name(Name that, Object constraint) {
1339            this.index = that.index;
1340            this.type = that.type;
1341            this.function = that.function;
1342            this.arguments = that.arguments;
1343            this.constraint = constraint;
1344            assert(constraint == null || isParam());  // only params have constraints
1345            assert(constraint == null || constraint instanceof BoundMethodHandle.SpeciesData || constraint instanceof Class);
1346        }
1347        Name(MethodHandle function, Object... arguments) {
1348            this(new NamedFunction(function), arguments);
1349        }
1350        Name(MethodType functionType, Object... arguments) {
1351            this(new NamedFunction(functionType), arguments);
1352            assert(arguments[0] instanceof Name && ((Name)arguments[0]).type == L_TYPE);
1353        }
1354        Name(MemberName function, Object... arguments) {
1355            this(new NamedFunction(function), arguments);
1356        }
1357        Name(NamedFunction function, Object... arguments) {
1358            this(-1, function.returnType(), function, arguments = Arrays.copyOf(arguments, arguments.length, Object[].class));
1359            assert(typesMatch(function, arguments));
1360        }
1361        /** Create a raw parameter of the given type, with an expected index. */
1362        Name(int index, BasicType type) {
1363            this(index, type, null, null);
1364        }
1365        /** Create a raw parameter of the given type. */
1366        Name(BasicType type) { this(-1, type); }
1367
1368        BasicType type() { return type; }
1369        int index() { return index; }
1370        boolean initIndex(int i) {
1371            if (index != i) {
1372                if (index != -1)  return false;
1373                index = (short)i;
1374            }
1375            return true;
1376        }
1377        char typeChar() {
1378            return type.btChar;
1379        }
1380
1381        void resolve() {
1382            if (function != null)
1383                function.resolve();
1384        }
1385
1386        Name newIndex(int i) {
1387            if (initIndex(i))  return this;
1388            return cloneWithIndex(i);
1389        }
1390        Name cloneWithIndex(int i) {
1391            Object[] newArguments = (arguments == null) ? null : arguments.clone();
1392            return new Name(i, type, function, newArguments).withConstraint(constraint);
1393        }
1394        Name withConstraint(Object constraint) {
1395            if (constraint == this.constraint)  return this;
1396            return new Name(this, constraint);
1397        }
1398        Name replaceName(Name oldName, Name newName) {  // FIXME: use replaceNames uniformly
1399            if (oldName == newName)  return this;
1400            @SuppressWarnings("LocalVariableHidesMemberVariable")
1401            Object[] arguments = this.arguments;
1402            if (arguments == null)  return this;
1403            boolean replaced = false;
1404            for (int j = 0; j < arguments.length; j++) {
1405                if (arguments[j] == oldName) {
1406                    if (!replaced) {
1407                        replaced = true;
1408                        arguments = arguments.clone();
1409                    }
1410                    arguments[j] = newName;
1411                }
1412            }
1413            if (!replaced)  return this;
1414            return new Name(function, arguments);
1415        }
1416        /** In the arguments of this Name, replace oldNames[i] pairwise by newNames[i].
1417         *  Limit such replacements to {@code start<=i<end}.  Return possibly changed self.
1418         */
1419        Name replaceNames(Name[] oldNames, Name[] newNames, int start, int end) {
1420            if (start >= end)  return this;
1421            @SuppressWarnings("LocalVariableHidesMemberVariable")
1422            Object[] arguments = this.arguments;
1423            boolean replaced = false;
1424        eachArg:
1425            for (int j = 0; j < arguments.length; j++) {
1426                if (arguments[j] instanceof Name) {
1427                    Name n = (Name) arguments[j];
1428                    int check = n.index;
1429                    // harmless check to see if the thing is already in newNames:
1430                    if (check >= 0 && check < newNames.length && n == newNames[check])
1431                        continue eachArg;
1432                    // n might not have the correct index: n != oldNames[n.index].
1433                    for (int i = start; i < end; i++) {
1434                        if (n == oldNames[i]) {
1435                            if (n == newNames[i])
1436                                continue eachArg;
1437                            if (!replaced) {
1438                                replaced = true;
1439                                arguments = arguments.clone();
1440                            }
1441                            arguments[j] = newNames[i];
1442                            continue eachArg;
1443                        }
1444                    }
1445                }
1446            }
1447            if (!replaced)  return this;
1448            return new Name(function, arguments);
1449        }
1450        void internArguments() {
1451            @SuppressWarnings("LocalVariableHidesMemberVariable")
1452            Object[] arguments = this.arguments;
1453            for (int j = 0; j < arguments.length; j++) {
1454                if (arguments[j] instanceof Name) {
1455                    Name n = (Name) arguments[j];
1456                    if (n.isParam() && n.index < INTERNED_ARGUMENT_LIMIT)
1457                        arguments[j] = internArgument(n);
1458                }
1459            }
1460        }
1461        boolean isParam() {
1462            return function == null;
1463        }
1464        boolean isConstantZero() {
1465            return !isParam() && arguments.length == 0 && function.isConstantZero();
1466        }
1467
1468        boolean refersTo(Class<?> declaringClass, String methodName) {
1469            return function != null &&
1470                    function.member() != null && function.member().refersTo(declaringClass, methodName);
1471        }
1472
1473        /**
1474         * Check if MemberName is a call to MethodHandle.invokeBasic.
1475         */
1476        boolean isInvokeBasic() {
1477            if (function == null)
1478                return false;
1479            if (arguments.length < 1)
1480                return false;  // must have MH argument
1481            MemberName member = function.member();
1482            return member != null && member.refersTo(MethodHandle.class, "invokeBasic") &&
1483                    !member.isPublic() && !member.isStatic();
1484        }
1485
1486        /**
1487         * Check if MemberName is a call to MethodHandle.linkToStatic, etc.
1488         */
1489        boolean isLinkerMethodInvoke() {
1490            if (function == null)
1491                return false;
1492            if (arguments.length < 1)
1493                return false;  // must have MH argument
1494            MemberName member = function.member();
1495            return member != null &&
1496                    member.getDeclaringClass() == MethodHandle.class &&
1497                    !member.isPublic() && member.isStatic() &&
1498                    member.getName().startsWith("linkTo");
1499        }
1500
1501        public String toString() {
1502            return (isParam()?"a":"t")+(index >= 0 ? index : System.identityHashCode(this))+":"+typeChar();
1503        }
1504        public String debugString() {
1505            String s = paramString();
1506            return (function == null) ? s : s + "=" + exprString();
1507        }
1508        public String paramString() {
1509            String s = toString();
1510            Object c = constraint;
1511            if (c == null)
1512                return s;
1513            if (c instanceof Class)  c = ((Class<?>)c).getSimpleName();
1514            return s + "/" + c;
1515        }
1516        public String exprString() {
1517            if (function == null)  return toString();
1518            StringBuilder buf = new StringBuilder(function.toString());
1519            buf.append("(");
1520            String cma = "";
1521            for (Object a : arguments) {
1522                buf.append(cma); cma = ",";
1523                if (a instanceof Name || a instanceof Integer)
1524                    buf.append(a);
1525                else
1526                    buf.append("(").append(a).append(")");
1527            }
1528            buf.append(")");
1529            return buf.toString();
1530        }
1531
1532        private boolean typesMatch(NamedFunction function, Object ... arguments) {
1533            assert(arguments.length == function.arity()) : "arity mismatch: arguments.length=" + arguments.length + " == function.arity()=" + function.arity() + " in " + debugString();
1534            for (int i = 0; i < arguments.length; i++) {
1535                assert (typesMatch(function.parameterType(i), arguments[i])) : "types don't match: function.parameterType(" + i + ")=" + function.parameterType(i) + ", arguments[" + i + "]=" + arguments[i] + " in " + debugString();
1536            }
1537            return true;
1538        }
1539
1540        private static boolean typesMatch(BasicType parameterType, Object object) {
1541            if (object instanceof Name) {
1542                return ((Name)object).type == parameterType;
1543            }
1544            switch (parameterType) {
1545                case I_TYPE:  return object instanceof Integer;
1546                case J_TYPE:  return object instanceof Long;
1547                case F_TYPE:  return object instanceof Float;
1548                case D_TYPE:  return object instanceof Double;
1549            }
1550            assert(parameterType == L_TYPE);
1551            return true;
1552        }
1553
1554        /** Return the index of the last occurrence of n in the argument array.
1555         *  Return -1 if the name is not used.
1556         */
1557        int lastUseIndex(Name n) {
1558            if (arguments == null)  return -1;
1559            for (int i = arguments.length; --i >= 0; ) {
1560                if (arguments[i] == n)  return i;
1561            }
1562            return -1;
1563        }
1564
1565        /** Return the number of occurrences of n in the argument array.
1566         *  Return 0 if the name is not used.
1567         */
1568        int useCount(Name n) {
1569            if (arguments == null)  return 0;
1570            int count = 0;
1571            for (int i = arguments.length; --i >= 0; ) {
1572                if (arguments[i] == n)  ++count;
1573            }
1574            return count;
1575        }
1576
1577        boolean contains(Name n) {
1578            return this == n || lastUseIndex(n) >= 0;
1579        }
1580
1581        public boolean equals(Name that) {
1582            if (this == that)  return true;
1583            if (isParam())
1584                // each parameter is a unique atom
1585                return false;  // this != that
1586            return
1587                //this.index == that.index &&
1588                this.type == that.type &&
1589                this.function.equals(that.function) &&
1590                Arrays.equals(this.arguments, that.arguments);
1591        }
1592        @Override
1593        public boolean equals(Object x) {
1594            return x instanceof Name && equals((Name)x);
1595        }
1596        @Override
1597        public int hashCode() {
1598            if (isParam())
1599                return index | (type.ordinal() << 8);
1600            return function.hashCode() ^ Arrays.hashCode(arguments);
1601        }
1602    }
1603
1604    /** Return the index of the last name which contains n as an argument.
1605     *  Return -1 if the name is not used.  Return names.length if it is the return value.
1606     */
1607    int lastUseIndex(Name n) {
1608        int ni = n.index, nmax = names.length;
1609        assert(names[ni] == n);
1610        if (result == ni)  return nmax;  // live all the way beyond the end
1611        for (int i = nmax; --i > ni; ) {
1612            if (names[i].lastUseIndex(n) >= 0)
1613                return i;
1614        }
1615        return -1;
1616    }
1617
1618    /** Return the number of times n is used as an argument or return value. */
1619    int useCount(Name n) {
1620        int nmax = names.length;
1621        int end = lastUseIndex(n);
1622        if (end < 0)  return 0;
1623        int count = 0;
1624        if (end == nmax) { count++; end--; }
1625        int beg = n.index() + 1;
1626        if (beg < arity)  beg = arity;
1627        for (int i = beg; i <= end; i++) {
1628            count += names[i].useCount(n);
1629        }
1630        return count;
1631    }
1632
1633    static Name argument(int which, BasicType type) {
1634        if (which >= INTERNED_ARGUMENT_LIMIT)
1635            return new Name(which, type);
1636        return INTERNED_ARGUMENTS[type.ordinal()][which];
1637    }
1638    static Name internArgument(Name n) {
1639        assert(n.isParam()) : "not param: " + n;
1640        assert(n.index < INTERNED_ARGUMENT_LIMIT);
1641        if (n.constraint != null)  return n;
1642        return argument(n.index, n.type);
1643    }
1644    static Name[] arguments(int extra, MethodType types) {
1645        int length = types.parameterCount();
1646        Name[] names = new Name[length + extra];
1647        for (int i = 0; i < length; i++)
1648            names[i] = argument(i, basicType(types.parameterType(i)));
1649        return names;
1650    }
1651    static final int INTERNED_ARGUMENT_LIMIT = 10;
1652    private static final Name[][] INTERNED_ARGUMENTS
1653            = new Name[ARG_TYPE_LIMIT][INTERNED_ARGUMENT_LIMIT];
1654    static {
1655        for (BasicType type : BasicType.ARG_TYPES) {
1656            int ord = type.ordinal();
1657            for (int i = 0; i < INTERNED_ARGUMENTS[ord].length; i++) {
1658                INTERNED_ARGUMENTS[ord][i] = new Name(i, type);
1659            }
1660        }
1661    }
1662
1663    private static final MemberName.Factory IMPL_NAMES = MemberName.getFactory();
1664
1665    static LambdaForm identityForm(BasicType type) {
1666        int ord = type.ordinal();
1667        LambdaForm form = LF_identity[ord];
1668        if (form != null) {
1669            return form;
1670        }
1671        createFormsFor(type);
1672        return LF_identity[ord];
1673    }
1674
1675    static LambdaForm zeroForm(BasicType type) {
1676        int ord = type.ordinal();
1677        LambdaForm form = LF_zero[ord];
1678        if (form != null) {
1679            return form;
1680        }
1681        createFormsFor(type);
1682        return LF_zero[ord];
1683    }
1684
1685    static NamedFunction identity(BasicType type) {
1686        int ord = type.ordinal();
1687        NamedFunction function = NF_identity[ord];
1688        if (function != null) {
1689            return function;
1690        }
1691        createFormsFor(type);
1692        return NF_identity[ord];
1693    }
1694
1695    static NamedFunction constantZero(BasicType type) {
1696        int ord = type.ordinal();
1697        NamedFunction function = NF_zero[ord];
1698        if (function != null) {
1699            return function;
1700        }
1701        createFormsFor(type);
1702        return NF_zero[ord];
1703    }
1704
1705    private static final @Stable LambdaForm[] LF_identity = new LambdaForm[TYPE_LIMIT];
1706    private static final @Stable LambdaForm[] LF_zero = new LambdaForm[TYPE_LIMIT];
1707    private static final @Stable NamedFunction[] NF_identity = new NamedFunction[TYPE_LIMIT];
1708    private static final @Stable NamedFunction[] NF_zero = new NamedFunction[TYPE_LIMIT];
1709
1710    private static synchronized void createFormsFor(BasicType type) {
1711        final int ord = type.ordinal();
1712        LambdaForm idForm = LF_identity[ord];
1713        if (idForm != null) {
1714            return;
1715        }
1716        char btChar = type.basicTypeChar();
1717        boolean isVoid = (type == V_TYPE);
1718        Class<?> btClass = type.btClass;
1719        MethodType zeType = MethodType.methodType(btClass);
1720        MethodType idType = (isVoid) ? zeType : zeType.appendParameterTypes(btClass);
1721
1722        // Look up symbolic names.  It might not be necessary to have these,
1723        // but if we need to emit direct references to bytecodes, it helps.
1724        // Zero is built from a call to an identity function with a constant zero input.
1725        MemberName idMem = new MemberName(LambdaForm.class, "identity_"+btChar, idType, REF_invokeStatic);
1726        MemberName zeMem = null;
1727        try {
1728            idMem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, idMem, null, NoSuchMethodException.class);
1729            if (!isVoid) {
1730                zeMem = new MemberName(LambdaForm.class, "zero_"+btChar, zeType, REF_invokeStatic);
1731                zeMem = IMPL_NAMES.resolveOrFail(REF_invokeStatic, zeMem, null, NoSuchMethodException.class);
1732            }
1733        } catch (IllegalAccessException|NoSuchMethodException ex) {
1734            throw newInternalError(ex);
1735        }
1736
1737        NamedFunction idFun;
1738        LambdaForm zeForm;
1739        NamedFunction zeFun;
1740
1741        // Create the LFs and NamedFunctions. Precompiling LFs to byte code is needed to break circular
1742        // bootstrap dependency on this method in case we're interpreting LFs
1743        if (isVoid) {
1744            Name[] idNames = new Name[] { argument(0, L_TYPE) };
1745            idForm = new LambdaForm(idMem.getName(), 1, idNames, VOID_RESULT, Kind.IDENTITY);
1746            idForm.compileToBytecode();
1747            idFun = new NamedFunction(idMem, SimpleMethodHandle.make(idMem.getInvocationType(), idForm));
1748
1749            zeForm = idForm;
1750            zeFun = idFun;
1751        } else {
1752            Name[] idNames = new Name[] { argument(0, L_TYPE), argument(1, type) };
1753            idForm = new LambdaForm(idMem.getName(), 2, idNames, 1, Kind.IDENTITY);
1754            idForm.compileToBytecode();
1755            idFun = new NamedFunction(idMem, MethodHandleImpl.makeIntrinsic(
1756                    idMem.getInvocationType(), idForm, MethodHandleImpl.Intrinsic.IDENTITY));
1757
1758            Object zeValue = Wrapper.forBasicType(btChar).zero();
1759            Name[] zeNames = new Name[] { argument(0, L_TYPE), new Name(idFun, zeValue) };
1760            zeForm = new LambdaForm(zeMem.getName(), 1, zeNames, 1, Kind.ZERO);
1761            zeForm.compileToBytecode();
1762            zeFun = new NamedFunction(zeMem, MethodHandleImpl.makeIntrinsic(
1763                    zeMem.getInvocationType(), zeForm, MethodHandleImpl.Intrinsic.ZERO));
1764        }
1765
1766        LF_zero[ord] = zeForm;
1767        NF_zero[ord] = zeFun;
1768        LF_identity[ord] = idForm;
1769        NF_identity[ord] = idFun;
1770
1771        assert(idFun.isIdentity());
1772        assert(zeFun.isConstantZero());
1773        assert(new Name(zeFun).isConstantZero());
1774    }
1775
1776    // Avoid appealing to ValueConversions at bootstrap time:
1777    private static int identity_I(int x) { return x; }
1778    private static long identity_J(long x) { return x; }
1779    private static float identity_F(float x) { return x; }
1780    private static double identity_D(double x) { return x; }
1781    private static Object identity_L(Object x) { return x; }
1782    private static void identity_V() { return; }
1783    private static int zero_I() { return 0; }
1784    private static long zero_J() { return 0; }
1785    private static float zero_F() { return 0; }
1786    private static double zero_D() { return 0; }
1787    private static Object zero_L() { return null; }
1788
1789    /**
1790     * Internal marker for byte-compiled LambdaForms.
1791     */
1792    /*non-public*/
1793    @Target(ElementType.METHOD)
1794    @Retention(RetentionPolicy.RUNTIME)
1795    @interface Compiled {
1796    }
1797
1798    /**
1799     * Internal marker for LambdaForm interpreter frames.
1800     */
1801    /*non-public*/
1802    @Target(ElementType.METHOD)
1803    @Retention(RetentionPolicy.RUNTIME)
1804    @interface Hidden {
1805    }
1806
1807    private static final HashMap<String,Integer> DEBUG_NAME_COUNTERS;
1808    static {
1809        if (debugEnabled())
1810            DEBUG_NAME_COUNTERS = new HashMap<>();
1811        else
1812            DEBUG_NAME_COUNTERS = null;
1813    }
1814
1815    static {
1816        // The Holder class will contain pre-generated forms resolved
1817        // using MemberName.getFactory(). However, that doesn't initialize the
1818        // class, which subtly breaks inlining etc. By forcing
1819        // initialization of the Holder class we avoid these issues.
1820        UNSAFE.ensureClassInitialized(Holder.class);
1821    }
1822
1823    /* Placeholder class for zero and identity forms generated ahead of time */
1824    final class Holder {}
1825
1826    // The following hack is necessary in order to suppress TRACE_INTERPRETER
1827    // during execution of the static initializes of this class.
1828    // Turning on TRACE_INTERPRETER too early will cause
1829    // stack overflows and other misbehavior during attempts to trace events
1830    // that occur during LambdaForm.<clinit>.
1831    // Therefore, do not move this line higher in this file, and do not remove.
1832    private static final boolean TRACE_INTERPRETER = MethodHandleStatics.TRACE_INTERPRETER;
1833}
1834