< prev index next >

src/java.base/share/classes/jdk/internal/foreign/abi/DirectSignatureShuffler.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. --- 1,7 ---- /* ! * Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation.
*** 89,101 **** private DirectSignatureShuffler(CallingSequence callingSequence, NativeMethodType nmt, ShuffleDirection direction) { checkCallingSequence(callingSequence); this.direction = direction; this.javaMethodType = nmt.methodType(); ! processType(RET_POS, nmt.returnType(), callingSequence.getReturnBindings(), direction.flip()); for (int i = 0 ; i < javaMethodType.parameterCount() ; i++) { ! processType(i, nmt.parameterType(i), callingSequence.getArgumentBindings(i), direction); } } static DirectSignatureShuffler javaToNativeShuffler(CallingSequence callingSequence, NativeMethodType nmt) { return new DirectSignatureShuffler(callingSequence, nmt, ShuffleDirection.JAVA_TO_NATIVE); --- 89,101 ---- private DirectSignatureShuffler(CallingSequence callingSequence, NativeMethodType nmt, ShuffleDirection direction) { checkCallingSequence(callingSequence); this.direction = direction; this.javaMethodType = nmt.methodType(); ! processType(RET_POS, nmt.returnType(), callingSequence.returnBindings(), direction.flip()); for (int i = 0 ; i < javaMethodType.parameterCount() ; i++) { ! processType(i, nmt.parameterType(i), callingSequence.argumentBindings(i), direction); } } static DirectSignatureShuffler javaToNativeShuffler(CallingSequence callingSequence, NativeMethodType nmt) { return new DirectSignatureShuffler(callingSequence, nmt, ShuffleDirection.JAVA_TO_NATIVE);
*** 140,150 **** } private static void checkCallingSequence(CallingSequence callingSequence) { if (callingSequence.returnsInMemory() || ! !callingSequence.getBindings(StorageClass.STACK_ARGUMENT_SLOT).isEmpty()) { throw new IllegalArgumentException("Unsupported non-scalarized calling sequence!"); } } private void processType(int sigPos, LayoutType<?> lt, List<ArgumentBinding> bindings, ShuffleDirection direction) { --- 140,150 ---- } private static void checkCallingSequence(CallingSequence callingSequence) { if (callingSequence.returnsInMemory() || ! !callingSequence.bindings(StorageClass.STACK_ARGUMENT_SLOT).isEmpty()) { throw new IllegalArgumentException("Unsupported non-scalarized calling sequence!"); } } private void processType(int sigPos, LayoutType<?> lt, List<ArgumentBinding> bindings, ShuffleDirection direction) {
*** 173,183 **** updateNativeMethodType(sigPos, long.class); adapters.add(direction.callbackAdapter(sigPos, lt)); } else if (Util.isCStruct(carrier)) { if (bindings.size() == 1) { ArgumentBinding binding = bindings.get(0); ! switch (binding.getStorage().getStorageClass()) { case INTEGER_ARGUMENT_REGISTER: case INTEGER_RETURN_REGISTER: updateNativeMethodType(sigPos, long.class); adapters.add(direction.longStructAdapter(sigPos, carrier)); break; --- 173,183 ---- updateNativeMethodType(sigPos, long.class); adapters.add(direction.callbackAdapter(sigPos, lt)); } else if (Util.isCStruct(carrier)) { if (bindings.size() == 1) { ArgumentBinding binding = bindings.get(0); ! switch (binding.storage().getStorageClass()) { case INTEGER_ARGUMENT_REGISTER: case INTEGER_RETURN_REGISTER: updateNativeMethodType(sigPos, long.class); adapters.add(direction.longStructAdapter(sigPos, carrier)); break;
*** 387,424 **** public static boolean acceptUpcall(NativeMethodType nmt, CallingSequence callingSequence) { return accept(nmt, callingSequence, ShuffleDirection.NATIVE_TO_JAVA); } private static boolean accept(NativeMethodType nmt, CallingSequence callingSequence, ShuffleDirection direction) { ! if (nmt.parameterCount() > direction.maxArity) return false; for (int i = 0 ; i < nmt.parameterCount(); i++) { ! List<ArgumentBinding> argumentBindings = callingSequence.getArgumentBindings(i); if (argumentBindings.size() != 1 || !isDirectBinding(argumentBindings.get(0))) { return false; } } ! List<ArgumentBinding> returnBindings = callingSequence.getReturnBindings(); ! if (returnBindings.isEmpty()) { ! return true; ! } else { ! return !callingSequence.returnsInMemory() && ! returnBindings.size() == 1 && isDirectBinding(returnBindings.get(0)); ! } } private static boolean isDirectBinding(ArgumentBinding binding) { ! switch (binding.getStorage().getStorageClass()) { case X87_RETURN_REGISTER: case STACK_ARGUMENT_SLOT: //arguments passed in memory not supported return false; case VECTOR_ARGUMENT_REGISTER: case VECTOR_RETURN_REGISTER: //avoid passing around floats as doubles as that leads to trouble ! return (binding.getMember().getType().bitsSize() / 8) == binding.getStorage().getSize(); default: return true; } } } --- 387,423 ---- public static boolean acceptUpcall(NativeMethodType nmt, CallingSequence callingSequence) { return accept(nmt, callingSequence, ShuffleDirection.NATIVE_TO_JAVA); } private static boolean accept(NativeMethodType nmt, CallingSequence callingSequence, ShuffleDirection direction) { ! if (nmt.isVarArgs() || ! callingSequence.returnsInMemory() || ! nmt.parameterCount() > direction.maxArity) return false; ! for (int i = 0 ; i < nmt.parameterCount(); i++) { ! List<ArgumentBinding> argumentBindings = callingSequence.argumentBindings(i); if (argumentBindings.size() != 1 || !isDirectBinding(argumentBindings.get(0))) { return false; } } ! List<ArgumentBinding> returnBindings = callingSequence.returnBindings(); ! return returnBindings.isEmpty() || ! (returnBindings.size() == 1 && isDirectBinding(returnBindings.get(0))); } private static boolean isDirectBinding(ArgumentBinding binding) { ! switch (binding.storage().getStorageClass()) { case X87_RETURN_REGISTER: case STACK_ARGUMENT_SLOT: //arguments passed in memory not supported return false; case VECTOR_ARGUMENT_REGISTER: case VECTOR_RETURN_REGISTER: //avoid passing around floats as doubles as that leads to trouble ! return (binding.argument().layout().bitsSize() / 8) == binding.storage().getSize(); default: return true; } } }
< prev index next >