< prev index next >

test/jdk/java/foreign/handles/invoker_module/handle/invoker/MethodHandleInvoker.java

Print this page
@@ -26,14 +26,15 @@
  import jdk.incubator.foreign.Addressable;
  import jdk.incubator.foreign.CLinker;
  import jdk.incubator.foreign.FunctionDescriptor;
  import jdk.incubator.foreign.MemoryAddress;
  import jdk.incubator.foreign.MemoryLayout;
- import jdk.incubator.foreign.MemoryLayouts;
+ import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.incubator.foreign.SegmentAllocator;
  import jdk.incubator.foreign.SymbolLookup;
+ import jdk.incubator.foreign.ValueLayout;
  
  import java.lang.invoke.MethodHandle;
  import java.lang.invoke.MethodHandles;
  import java.lang.invoke.MethodType;
  import java.nio.charset.Charset;

@@ -50,36 +51,52 @@
          } catch (IllegalCallerException ex) {
              if (!ex.getMessage().contains("lookup_module")) {
                  throw new AssertionError("Caller module is not lookup_module!");
              }
          } catch (Throwable ex) {
-             throw new AssertionError("Call to restricted method did not fail as expected!");
+             throw new AssertionError("Call to restricted method did not fail as expected!", ex);
          }
      }
  
      static final Map<Class<?>, Object> DEFAULT_VALUES = new HashMap<>();
  
      static <Z> void addDefaultMapping(Class<Z> carrier, Z value) {
          DEFAULT_VALUES.put(carrier, value);
      }
  
      static {
-         addDefaultMapping(CLinker.class, CLinker.getInstance());
-         addDefaultMapping(long.class, 0L);
+         addDefaultMapping(CLinker.class, CLinker.systemCLinker());
          addDefaultMapping(Path.class, Path.of("nonExistent"));
          addDefaultMapping(String.class, "Hello!");
          addDefaultMapping(Runnable.class, () -> {});
          addDefaultMapping(MethodHandle.class, MethodHandles.identity(int.class));
          addDefaultMapping(Charset.class, Charset.defaultCharset());
          addDefaultMapping(MethodType.class, MethodType.methodType(void.class));
          addDefaultMapping(MemoryAddress.class, MemoryAddress.NULL);
          addDefaultMapping(Addressable.class, MemoryAddress.NULL);
-         addDefaultMapping(MemoryLayout.class, MemoryLayouts.JAVA_INT);
+         addDefaultMapping(MemoryLayout.class, ValueLayout.JAVA_INT);
          addDefaultMapping(FunctionDescriptor.class, FunctionDescriptor.ofVoid());
          addDefaultMapping(SymbolLookup.class, SymbolLookup.loaderLookup());
          addDefaultMapping(ResourceScope.class, ResourceScope.newImplicitScope());
-         addDefaultMapping(SegmentAllocator.class, (size, align) -> null);
+         addDefaultMapping(SegmentAllocator.class, SegmentAllocator.prefixAllocator(MemorySegment.ofArray(new byte[10])));
+         addDefaultMapping(ValueLayout.OfByte.class, ValueLayout.JAVA_BYTE);
+         addDefaultMapping(ValueLayout.OfBoolean.class, ValueLayout.JAVA_BOOLEAN);
+         addDefaultMapping(ValueLayout.OfChar.class, ValueLayout.JAVA_CHAR);
+         addDefaultMapping(ValueLayout.OfShort.class, ValueLayout.JAVA_SHORT);
+         addDefaultMapping(ValueLayout.OfInt.class, ValueLayout.JAVA_INT);
+         addDefaultMapping(ValueLayout.OfFloat.class, ValueLayout.JAVA_FLOAT);
+         addDefaultMapping(ValueLayout.OfLong.class, ValueLayout.JAVA_LONG);
+         addDefaultMapping(ValueLayout.OfDouble.class, ValueLayout.JAVA_DOUBLE);
+         addDefaultMapping(ValueLayout.OfAddress.class, ValueLayout.ADDRESS);
+         addDefaultMapping(byte.class, (byte)0);
+         addDefaultMapping(boolean.class, true);
+         addDefaultMapping(char.class, (char)0);
+         addDefaultMapping(short.class, (short)0);
+         addDefaultMapping(int.class, 0);
+         addDefaultMapping(float.class, 0f);
+         addDefaultMapping(long.class, 0L);
+         addDefaultMapping(double.class, 0d);
      }
  
      static Object[] makeArgs(MethodType type) {
          return type.parameterList().stream()
                  .map(MethodHandleInvoker::makeArg)
< prev index next >