Making FMA more flexible

Ty Young youngty1997 at gmail.com
Wed Apr 29 17:58:00 UTC 2020


On 4/29/20 12:36 PM, Maurizio Cimadamore wrote:
>
> On 29/04/2020 18:22, Ty Young wrote:
>>
>> On 4/29/20 11:37 AM, Maurizio Cimadamore wrote:
>>
>>
>> *snip*
>>
>>
>>> The function descriptor has to be passed to SystemABI to create the 
>>> handle in the first place. At this (low) level, just primitive 
>>> types, segments and addresses.
>>>
>>> *after* you get the method handle, you can adapt and obtain a new 
>>> (higher-level) handle.
>>
>>
>> Thanks.
>>
>>
>> Question: does MethodHandle have the ability to reference a 
>> yet-to-be-implemented method as a MethodHandle? I'm trying to use an 
>> abstract class to handle the business logic and just have individual 
>> classes implement(via extends) the "callback" method, but it fails, 
>> saying it can't be found. Is there a specific code path that needs to 
>> be taken?
>
> You should be able to create a method handle out of an 
> abstract/interface method, which will do the right thing on dispatch.
>
> Perhaps paste some code or pointers and maybe I'll be able to point 
> you in the right direction.


Right, just wanted to make sure there wasn't a specific method I needed 
for it.


Interface:


public interface NativeCallback extends NativeObject
{
     public void callback(NativeObject... args);
}


public abstract class AbstractNativeCallback implements NativeCallback
{
     private final MethodType type;
     private final MethodHandle handle;
     private final FunctionDescriptor descriptor;
     private final MemoryAddress address;

     public AbstractNativeCallback() throws NoSuchMethodException, 
IllegalAccessException
     {
         this.type = MethodType.methodType(void.class, 
MemoryAddress[].class);
         this.handle = 
MethodHandles.lookup().findVirtual(NativeCallback.class, "callback", type);

         MemoryLayout[] classes = new 
MemoryLayout[this.handle.type().parameterCount()-1];

         for(int i = 1; i < this.handle.type().parameterCount()-1; i++)
             classes[i] = 
PlatformTypeLayouts.convert(this.handle.type().parameterType(i));

         this.descriptor = FunctionDescriptor.ofVoid(classes);

         this.address = SystemABI.getSystemABI().upcallStub(this.handle, 
this.descriptor);
     }

     @Override
     public MemoryAddress getAddress()
     {
         return this.address;
     }

}


My issue here I guess is that the actual method's MethodType is 
different than what FMA will allow(MemoryAddress). Am I using the wrong 
Lookup method?


>
> Maurizio
>
>>
>>
>>>
>>> Maurizio
>>>


More information about the panama-dev mailing list