< prev index next >

src/java.base/share/classes/jdk/experimental/value/ValueType.java

Print this page
rev 17246 : [mq]: findWither-access


 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         // @@@ special access check for read/write access
 283         //force access-check
 284         lookup.findGetter(boxClass(), name, type);


 285         return result;
 286     }



 287 
 288     public MethodHandle unbox() {
 289         ValueHandleKey key = ValueHandleKind.UNBOX.key();
 290         MethodHandle result = handleMap.get(key);
 291         if (result == null) {
 292             result = MethodHandleBuilder.loadCode(boxLookup, mhName("unbox"), MethodType.methodType(valueClass(), boxClass()),
 293                     C -> {
 294                         C.load(0).vunbox(valueClass()).vreturn();
 295                     });
 296             handleMap.put(key, result);
 297         }
 298         return result;
 299     }
 300 
 301     public MethodHandle box() {
 302         ValueHandleKey key = ValueHandleKind.BOX.key();
 303         MethodHandle result = handleMap.get(key);
 304         if (result == null) {
 305             result = MethodHandleBuilder.loadCode(boxLookup, mhName("box"), MethodType.methodType(boxClass(), valueClass()),
 306                     C -> {




 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     }
 292 
 293     public MethodHandle unbox() {
 294         ValueHandleKey key = ValueHandleKind.UNBOX.key();
 295         MethodHandle result = handleMap.get(key);
 296         if (result == null) {
 297             result = MethodHandleBuilder.loadCode(boxLookup, mhName("unbox"), MethodType.methodType(valueClass(), boxClass()),
 298                     C -> {
 299                         C.load(0).vunbox(valueClass()).vreturn();
 300                     });
 301             handleMap.put(key, result);
 302         }
 303         return result;
 304     }
 305 
 306     public MethodHandle box() {
 307         ValueHandleKey key = ValueHandleKind.BOX.key();
 308         MethodHandle result = handleMap.get(key);
 309         if (result == null) {
 310             result = MethodHandleBuilder.loadCode(boxLookup, mhName("box"), MethodType.methodType(boxClass(), valueClass()),
 311                     C -> {


< prev index next >