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