252 C.withLocal("res", "I");
253 C.const_(1).store("res");
254 for (Field f : valueFields()) {
255 String desc = BytecodeDescriptor.unparse(f.getType());
256 C.vload(0).vgetfield(valueClass(), f.getName(), desc);
257 if (f.getType().isPrimitive()) {
258 C.invokestatic(Wrapper.asWrapperType(f.getType()), "hashCode", "(" + desc + ")I", false);
259 } else {
260 C.invokestatic(Objects.class, "hashCode", "(Ljava/lang/Object;)I", false);
261 }
262 C.load("res").const_(31).imul();
263 C.iadd().store("res");
264 }
265 C.load("res").ireturn();
266 });
267 handleMap.put(key, result);
268 }
269 return result;
270 }
271
272 public MethodHandle findWither(Lookup lookup, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException {
273 ValueHandleKey key = ValueHandleKind.WITHER.key(List.of(name, type));
274 MethodHandle result = handleMap.get(key);
275 if (result == null) {
276 String fieldType = BytecodeDescriptor.unparse(type);
277
278 result = MethodHandleBuilder.loadCode(valueLookup, mhName("wither$" + name), MethodType.methodType(valueClass(), valueClass(), type),
279 C -> C.vload(0).load(1).vwithfield(valueClass(), name, fieldType).vreturn());
280 handleMap.put(key, result);
281 }
282
283 // Allow access if the lookup class is the VCC or DVT and the lookup
284 // has private access
285 Class<?> lc = lookup.lookupClass();
286 if (lookup.hasPrivateAccess() && (valueClass() == lc || boxClass() == lc)) {
287 return result;
288 }
289 throw new IllegalAccessException(String.format("Class %s does not have vwithfield access to field %s.%s",
290 lc.getName(), boxClass().getName(), name));
291 }
|
252 C.withLocal("res", "I");
253 C.const_(1).store("res");
254 for (Field f : valueFields()) {
255 String desc = BytecodeDescriptor.unparse(f.getType());
256 C.vload(0).vgetfield(valueClass(), f.getName(), desc);
257 if (f.getType().isPrimitive()) {
258 C.invokestatic(Wrapper.asWrapperType(f.getType()), "hashCode", "(" + desc + ")I", false);
259 } else {
260 C.invokestatic(Objects.class, "hashCode", "(Ljava/lang/Object;)I", false);
261 }
262 C.load("res").const_(31).imul();
263 C.iadd().store("res");
264 }
265 C.load("res").ireturn();
266 });
267 handleMap.put(key, result);
268 }
269 return result;
270 }
271
272 // ()__Value
273 public MethodHandle findConstructor(Lookup lookup, MethodType type) throws NoSuchMethodException, IllegalAccessException {
274 return MethodHandles.filterReturnValue(lookup.findConstructor(boxClass(), type), unbox());
275 }
276
277 // (__Value, T)__Value
278 public MethodHandle findWither(Lookup lookup, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException {
279 ValueHandleKey key = ValueHandleKind.WITHER.key(List.of(name, type));
280 MethodHandle result = handleMap.get(key);
281 if (result == null) {
282 String fieldType = BytecodeDescriptor.unparse(type);
283
284 result = MethodHandleBuilder.loadCode(valueLookup, mhName("wither$" + name), MethodType.methodType(valueClass(), valueClass(), type),
285 C -> C.vload(0).load(1).vwithfield(valueClass(), name, fieldType).vreturn());
286 handleMap.put(key, result);
287 }
288
289 // Allow access if the lookup class is the VCC or DVT and the lookup
290 // has private access
291 Class<?> lc = lookup.lookupClass();
292 if (lookup.hasPrivateAccess() && (valueClass() == lc || boxClass() == lc)) {
293 return result;
294 }
295 throw new IllegalAccessException(String.format("Class %s does not have vwithfield access to field %s.%s",
296 lc.getName(), boxClass().getName(), name));
297 }
|