3232import sun .invoke .util .VerifyAccess ;
3333import sun .security .action .GetBooleanAction ;
3434
35- import java .nio .charset .StandardCharsets ;
3635import java .io .Serializable ;
3736import java .lang .constant .ConstantDescs ;
3837import java .lang .reflect .Modifier ;
3938import java .util .LinkedHashSet ;
4039import java .util .Set ;
41- import java .util .StringJoiner ;
42- import java .util .zip .CRC32 ;
4340
4441import static java .lang .invoke .MethodHandleStatics .CLASSFILE_VERSION ;
4542import static java .lang .invoke .MethodHandles .Lookup .ClassOption .NESTMATE ;
8784
8885 private static final boolean disableEagerInitialization ;
8986
90- private static final boolean generateStableLambdaNames ;
91-
92- private static final int mask1 = 0b10101010;
93- private static final int mask2 = 0b01010101;
94-
9587 // condy to load implMethod from class data
9688 private static final ConstantDynamic implMethodCondy ;
9789
10597 final String disableEagerInitializationKey = "jdk.internal.lambda.disableEagerInitialization" ;
10698 disableEagerInitialization = GetBooleanAction .privilegedGetProperty (disableEagerInitializationKey );
10799
108- final String generateStableLambdaNamesKey = "jdk.internal.lambda.generateStableLambdaNames" ;
109- generateStableLambdaNames = GetBooleanAction .privilegedGetProperty (generateStableLambdaNamesKey );
110-
111100 // condy to load implMethod from class data
112101 MethodType classDataMType = methodType (Object .class , MethodHandles .Lookup .class , String .class , Class .class );
113102 Handle classDataBsm = new Handle (H_INVOKESTATIC , Type .getInternalName (MethodHandles .class ), "classData" ,
@@ -183,7 +172,7 @@ public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
183172 implMethodName = implInfo .getName ();
184173 implMethodDesc = implInfo .getMethodType ().toMethodDescriptorString ();
185174 constructorType = factoryType .changeReturnType (Void .TYPE );
186- lambdaClassName = generateStableLambdaNames ? stableLambdaClassName ( targetClass ) : lambdaClassName (targetClass );
175+ lambdaClassName = lambdaClassName (targetClass );
187176 // If the target class invokes a protected method inherited from a
188177 // superclass in a different package, or does 'invokespecial', the
189178 // lambda class has no access to the resolved method. Instead, we need
@@ -208,10 +197,6 @@ public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
208197 }
209198
210199 private static String lambdaClassName (Class <?> targetClass ) {
211- return createNameFromTargetClass (targetClass );
212- }
213-
214- private static String createNameFromTargetClass (Class <?> targetClass ) {
215200 String name = targetClass .getName ();
216201 if (targetClass .isHidden ()) {
217202 // use the original class name
@@ -220,78 +205,6 @@ private static String createNameFromTargetClass(Class<?> targetClass) {
220205 return name .replace ('.' , '/' ) + "$$Lambda" ;
221206 }
222207
223- /**
224- * Create a stable name for the lambda class.
225- * When CDS archiving is enabled, lambda classes
226- * are stored in the archive using some parameters from
227- * the InnerClassLambdaMetafactory. To distinguish between
228- * two lambdas, even when CDS archiving is disabled,
229- * use a superset of those parameters to create a stable name.
230- *
231- * Concatenate all the parameters chosen for the stable name,
232- * and hash them into 64-bit hash value.
233- * Any additional changes to this method will result in unstable
234- * hash values across different versions. Thus, every change
235- * to this method should be regarded as a backward incompatible change.
236- *
237- * No matter what hash function we use, there is a possibility of
238- * collisions in names. We expect a relatively low number of lambdas
239- * per class. Thus, we don't expect to have collisions using the described
240- * hash function. Every tool that uses this feature should handle potential
241- * collisions on its own. There is no guarantee that names will be unique,
242- * only that they will be stable (identical in every run).
243- *
244- * @return a stable name for the created lambda class.
245- */
246- private String stableLambdaClassName (Class <?> targetClass ) {
247- String name = createNameFromTargetClass (targetClass );
248-
249- StringBuilder hashData1 = new StringBuilder (), hashData2 = new StringBuilder ();
250- appendData (hashData1 , hashData2 , interfaceMethodName );
251- appendData (hashData1 , hashData2 , getQualifiedSignature (factoryType ));
252- appendData (hashData1 , hashData2 , getQualifiedSignature (interfaceMethodType ));
253- appendData (hashData1 , hashData2 , implementation .internalMemberName ().toString ());
254- appendData (hashData1 , hashData2 , getQualifiedSignature (dynamicMethodType ));
255-
256- for (Class <?> clazz : altInterfaces ) {
257- appendData (hashData1 , hashData2 , clazz .getName ());
258- }
259-
260- for (MethodType method : altMethods ) {
261- appendData (hashData1 , hashData2 , getQualifiedSignature (method ));
262- }
263-
264- return name + hashToHexString (hashData1 .toString (), hashData2 .toString ());
265- }
266-
267- private void appendData (StringBuilder hashData1 , StringBuilder hashData2 , String data ) {
268- for (int i = 0 ; i < data .length (); i ++) {
269- hashData1 .append ((char )(data .charAt (i ) & mask1 ));
270- hashData2 .append ((char )(data .charAt (i ) & mask2 ));
271- }
272- }
273-
274- private long hashStringToLong (String hashData ) {
275- CRC32 crc32 = new CRC32 ();
276- crc32 .update (hashData .getBytes (StandardCharsets .UTF_8 ));
277- return crc32 .getValue ();
278- }
279-
280- private String hashToHexString (String hashData1 , String hashData2 ) {
281- long hashValueData1 = hashStringToLong (hashData1 );
282- long hashValueData2 = hashStringToLong (hashData2 );
283- return Long .toHexString (hashValueData1 | (hashValueData2 << 32 ));
284- }
285-
286- private String getQualifiedSignature (MethodType type ) {
287- StringJoiner sj = new StringJoiner ("," , "(" , ")" + type .returnType ().getName ());
288- Class <?>[] ptypes = type .ptypes ();
289- for (int i = 0 ; i < ptypes .length ; i ++) {
290- sj .add (ptypes [i ].getName ());
291- }
292- return sj .toString ();
293- }
294-
295208 /**
296209 * Build the CallSite. Generate a class file which implements the functional
297210 * interface, define the class, if there are no parameters create an instance
0 commit comments