1
1
/*
2
- * Copyright (c) 2011, 2024 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 2011, 2025 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
@@ -245,8 +245,8 @@ private static boolean checkBasicType() {
245
245
246
246
enum Kind {
247
247
GENERIC ("invoke" ),
248
- ZERO ("zero" ),
249
248
IDENTITY ("identity" ),
249
+ CONSTANT ("constant" ),
250
250
BOUND_REINVOKER ("BMH.reinvoke" , "reinvoke" ),
251
251
REINVOKER ("MH.reinvoke" , "reinvoke" ),
252
252
DELEGATE ("MH.delegate" , "delegate" ),
@@ -372,31 +372,13 @@ static LambdaForm create(int arity, Name[] names, boolean forceInline, Kind kind
372
372
}
373
373
374
374
private static LambdaForm createBlankForType (MethodType mt ) {
375
- // Make a blank lambda form, which returns a constant zero or null .
375
+ // Make a dummy blank lambda form.
376
376
// It is used as a template for managing the invocation of similar forms that are non-empty.
377
377
// Called only from getPreparedForm.
378
- int arity = mt .parameterCount ();
379
- int result = (mt .returnType () == void .class || mt .returnType () == Void .class ) ? VOID_RESULT : arity ;
380
- Name [] names = buildEmptyNames (arity , mt , result == VOID_RESULT );
381
- boolean canInterpret = normalizeNames (arity , names );
382
- LambdaForm form = new LambdaForm (arity , result , DEFAULT_FORCE_INLINE , DEFAULT_CUSTOMIZED , names , Kind .ZERO );
383
- assert (form .nameRefsAreLegal () && form .isEmpty () && isValidSignature (form .basicTypeSignature ()));
384
- if (!canInterpret ) {
385
- form .compileToBytecode ();
386
- }
378
+ LambdaForm form = new LambdaForm (0 , 0 , DEFAULT_FORCE_INLINE , DEFAULT_CUSTOMIZED , new Name [0 ], Kind .GENERIC );
387
379
return form ;
388
380
}
389
381
390
- private static Name [] buildEmptyNames (int arity , MethodType mt , boolean isVoid ) {
391
- Name [] names = arguments (isVoid ? 0 : 1 , mt );
392
- if (!isVoid ) {
393
- Name zero = new Name (constantZero (basicType (mt .returnType ())));
394
- names [arity ] = zero .withIndex (arity );
395
- }
396
- assert (namesOK (arity , names ));
397
- return names ;
398
- }
399
-
400
382
private static int fixResult (int result , Name [] names ) {
401
383
if (result == LAST_RESULT )
402
384
result = names .length - 1 ; // might still be void
@@ -1011,15 +993,6 @@ private boolean resultCheck(Object[] argumentValues, Object result) {
1011
993
return true ;
1012
994
}
1013
995
1014
- private boolean isEmpty () {
1015
- if (result < 0 )
1016
- return (names .length == arity );
1017
- else if (result == arity && names .length == arity + 1 )
1018
- return names [arity ].isConstantZero ();
1019
- else
1020
- return false ;
1021
- }
1022
-
1023
996
public String toString () {
1024
997
return debugString (-1 );
1025
998
}
@@ -1251,10 +1224,6 @@ public boolean isIdentity() {
1251
1224
return this .equals (identity (returnType ()));
1252
1225
}
1253
1226
1254
- public boolean isConstantZero () {
1255
- return this .equals (constantZero (returnType ()));
1256
- }
1257
-
1258
1227
public MethodHandleImpl .Intrinsic intrinsicName () {
1259
1228
return resolvedHandle != null
1260
1229
? resolvedHandle .intrinsicName ()
@@ -1453,9 +1422,6 @@ void internArguments() {
1453
1422
boolean isParam () {
1454
1423
return function == null ;
1455
1424
}
1456
- boolean isConstantZero () {
1457
- return !isParam () && arguments .length == 0 && function .isConstantZero ();
1458
- }
1459
1425
1460
1426
boolean refersTo (Class <?> declaringClass , String methodName ) {
1461
1427
return function != null &&
@@ -1662,50 +1628,45 @@ static LambdaForm identityForm(BasicType type) {
1662
1628
if (form != null ) {
1663
1629
return form ;
1664
1630
}
1665
- createFormsFor (type );
1631
+ createIdentityForm (type );
1666
1632
return LF_identity [ord ];
1667
1633
}
1668
1634
1669
- static LambdaForm zeroForm (BasicType type ) {
1670
- int ord = type .ordinal ();
1671
- LambdaForm form = LF_zero [ord ];
1672
- if (form != null ) {
1673
- return form ;
1674
- }
1675
- createFormsFor (type );
1676
- return LF_zero [ord ];
1677
- }
1678
-
1679
1635
static NamedFunction identity (BasicType type ) {
1680
1636
int ord = type .ordinal ();
1681
1637
NamedFunction function = NF_identity [ord ];
1682
1638
if (function != null ) {
1683
1639
return function ;
1684
1640
}
1685
- createFormsFor (type );
1641
+ createIdentityForm (type );
1686
1642
return NF_identity [ord ];
1687
1643
}
1688
1644
1689
- static NamedFunction constantZero (BasicType type ) {
1690
- int ord = type .ordinal ();
1691
- NamedFunction function = NF_zero [ord ];
1692
- if (function != null ) {
1693
- return function ;
1694
- }
1695
- createFormsFor (type );
1696
- return NF_zero [ord ];
1645
+ static LambdaForm constantForm (BasicType type ) {
1646
+ assert type != null && type != V_TYPE : type ;
1647
+ var cached = LF_constant [type .ordinal ()];
1648
+ if (cached != null )
1649
+ return cached ;
1650
+ return createConstantForm (type );
1651
+ }
1652
+
1653
+ private static LambdaForm createConstantForm (BasicType type ) {
1654
+ UNSAFE .ensureClassInitialized (BoundMethodHandle .class ); // defend access to SimpleMethodHandle
1655
+ var species = SimpleMethodHandle .BMH_SPECIES .extendWith (type );
1656
+ var carrier = argument (0 , L_TYPE ).withConstraint (species ); // BMH bound with data
1657
+ Name [] constNames = new Name [] { carrier , new Name (species .getterFunction (0 ), carrier ) };
1658
+ return LF_constant [type .ordinal ()] = create (1 , constNames , Kind .CONSTANT );
1697
1659
}
1698
1660
1699
1661
private static final @ Stable LambdaForm [] LF_identity = new LambdaForm [TYPE_LIMIT ];
1700
- private static final @ Stable LambdaForm [] LF_zero = new LambdaForm [TYPE_LIMIT ];
1701
1662
private static final @ Stable NamedFunction [] NF_identity = new NamedFunction [TYPE_LIMIT ];
1702
- private static final @ Stable NamedFunction [] NF_zero = new NamedFunction [ TYPE_LIMIT ];
1663
+ private static final @ Stable LambdaForm [] LF_constant = new LambdaForm [ ARG_TYPE_LIMIT ]; // no void
1703
1664
1704
- private static final Object createFormsLock = new Object ();
1705
- private static void createFormsFor (BasicType type ) {
1665
+ private static final Object createIdentityFormLock = new Object ();
1666
+ private static void createIdentityForm (BasicType type ) {
1706
1667
// Avoid racy initialization during bootstrap
1707
1668
UNSAFE .ensureClassInitialized (BoundMethodHandle .class );
1708
- synchronized (createFormsLock ) {
1669
+ synchronized (createIdentityFormLock ) {
1709
1670
final int ord = type .ordinal ();
1710
1671
LambdaForm idForm = LF_identity [ord ];
1711
1672
if (idForm != null ) {
@@ -1714,27 +1675,18 @@ private static void createFormsFor(BasicType type) {
1714
1675
char btChar = type .basicTypeChar ();
1715
1676
boolean isVoid = (type == V_TYPE );
1716
1677
Class <?> btClass = type .btClass ;
1717
- MethodType zeType = MethodType .methodType (btClass );
1718
- MethodType idType = (isVoid ) ? zeType : MethodType .methodType (btClass , btClass );
1678
+ MethodType idType = (isVoid ) ? MethodType .methodType (btClass ) : MethodType .methodType (btClass , btClass );
1719
1679
1720
1680
// Look up symbolic names. It might not be necessary to have these,
1721
1681
// but if we need to emit direct references to bytecodes, it helps.
1722
- // Zero is built from a call to an identity function with a constant zero input.
1723
1682
MemberName idMem = new MemberName (LambdaForm .class , "identity_" +btChar , idType , REF_invokeStatic );
1724
- MemberName zeMem = null ;
1725
1683
try {
1726
1684
idMem = IMPL_NAMES .resolveOrFail (REF_invokeStatic , idMem , null , LM_TRUSTED , NoSuchMethodException .class );
1727
- if (!isVoid ) {
1728
- zeMem = new MemberName (LambdaForm .class , "zero_" +btChar , zeType , REF_invokeStatic );
1729
- zeMem = IMPL_NAMES .resolveOrFail (REF_invokeStatic , zeMem , null , LM_TRUSTED , NoSuchMethodException .class );
1730
- }
1731
1685
} catch (IllegalAccessException |NoSuchMethodException ex ) {
1732
1686
throw newInternalError (ex );
1733
1687
}
1734
1688
1735
1689
NamedFunction idFun ;
1736
- LambdaForm zeForm ;
1737
- NamedFunction zeFun ;
1738
1690
1739
1691
// Create the LFs and NamedFunctions. Precompiling LFs to byte code is needed to break circular
1740
1692
// bootstrap dependency on this method in case we're interpreting LFs
@@ -1743,32 +1695,18 @@ private static void createFormsFor(BasicType type) {
1743
1695
idForm = LambdaForm .create (1 , idNames , VOID_RESULT , Kind .IDENTITY );
1744
1696
idForm .compileToBytecode ();
1745
1697
idFun = new NamedFunction (idMem , SimpleMethodHandle .make (idMem .getInvocationType (), idForm ));
1746
-
1747
- zeForm = idForm ;
1748
- zeFun = idFun ;
1749
1698
} else {
1750
1699
Name [] idNames = new Name [] { argument (0 , L_TYPE ), argument (1 , type ) };
1751
1700
idForm = LambdaForm .create (2 , idNames , 1 , Kind .IDENTITY );
1752
1701
idForm .compileToBytecode ();
1753
- idFun = new NamedFunction (idMem , MethodHandleImpl .makeIntrinsic (SimpleMethodHandle . make ( idMem .getInvocationType (), idForm ) ,
1702
+ idFun = new NamedFunction (idMem , MethodHandleImpl .makeIntrinsic (idMem .getInvocationType (), idForm ,
1754
1703
MethodHandleImpl .Intrinsic .IDENTITY ));
1755
-
1756
- Object zeValue = Wrapper .forBasicType (btChar ).zero ();
1757
- Name [] zeNames = new Name [] { argument (0 , L_TYPE ), new Name (idFun , zeValue ) };
1758
- zeForm = LambdaForm .create (1 , zeNames , 1 , Kind .ZERO );
1759
- zeForm .compileToBytecode ();
1760
- zeFun = new NamedFunction (zeMem , MethodHandleImpl .makeIntrinsic (SimpleMethodHandle .make (zeMem .getInvocationType (), zeForm ),
1761
- MethodHandleImpl .Intrinsic .ZERO ));
1762
1704
}
1763
1705
1764
- LF_zero [ord ] = zeForm ;
1765
- NF_zero [ord ] = zeFun ;
1766
1706
LF_identity [ord ] = idForm ;
1767
1707
NF_identity [ord ] = idFun ;
1768
1708
1769
1709
assert (idFun .isIdentity ());
1770
- assert (zeFun .isConstantZero ());
1771
- assert (new Name (zeFun ).isConstantZero ());
1772
1710
}
1773
1711
}
1774
1712
@@ -1779,12 +1717,6 @@ private static void createFormsFor(BasicType type) {
1779
1717
private static double identity_D (double x ) { return x ; }
1780
1718
private static Object identity_L (Object x ) { return x ; }
1781
1719
private static void identity_V () { return ; }
1782
- private static int zero_I () { return 0 ; }
1783
- private static long zero_J () { return 0 ; }
1784
- private static float zero_F () { return 0 ; }
1785
- private static double zero_D () { return 0 ; }
1786
- private static Object zero_L () { return null ; }
1787
-
1788
1720
/**
1789
1721
* Internal marker for byte-compiled LambdaForms.
1790
1722
*/
@@ -1814,7 +1746,7 @@ private static void createFormsFor(BasicType type) {
1814
1746
UNSAFE .ensureClassInitialized (Holder .class );
1815
1747
}
1816
1748
1817
- /* Placeholder class for zero and identity forms generated ahead of time */
1749
+ /* Placeholder class for identity and constant forms generated ahead of time */
1818
1750
final class Holder {}
1819
1751
1820
1752
// The following hack is necessary in order to suppress TRACE_INTERPRETER
1 commit comments
openjdk-notifier[bot] commentedon Mar 7, 2025
Review
Issues