[code-reflection] RFR: Make Quotable a marker interface [v6]
Mourad Abbay
mabbay at openjdk.org
Mon Jan 13 15:32:54 UTC 2025
On Sat, 11 Jan 2025 00:20:08 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:
>> Mourad Abbay has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Revert to defining an interface for Quotable lambda in the interpreter
>
> src/jdk.incubator.code/share/classes/jdk/incubator/code/interpreter/Interpreter.java line 499:
>
>> 497: // that's why we define an interface that contains the method, so that proxy class has it
>> 498: // and the code of Op.ofQuotable works
>> 499: byte[] bytes = ClassFile.of().build(ClassDesc.of("I" + System.nanoTime()), classBuilder -> {
>
> This can potentially generate many many classes that in effect are thrown away but not GC'ed. We should avoid that. Before defining the class we can check if the class is already defined by the lookup class's class loader, and if not define it using the lookup. Ideally we would define a hidden class, but then we cannot query via the class loader if it is defined and would need an alternate tracking mechanism e.g., weak hash map of class loader to class. Regardless this needs to be thread safe. The class name can be "I + [system identify hash code of the class loader]" (perhaps choose a prefix that is not possible to express in source).
>
> There is an alternative simpler compromise that might work (if the accessibility gods are in our favor) where the proxy logic bleeds into the `Op:ofQuotable` method. Proxy provides methods to check if a class is a proxy class and if so it is possible to obtain the `InvocationHandler` instance for a proxy whose class is the proxy class. This is currently a lambda expression but we could instead make it an anon inner class and implement the required method.
>
> In `Op:ofMethod` we would do:
>
>
> Object oq = q;
> if (Proxy.isProxyClass(oq.getClass())) {
> oq = Proxy.getInvocationHandler(oq);
> }
>
> try {
> method = oq.getClass().getMethod("quoted");
> } catch (NoSuchMethodException e) {
> throw new RuntimeException(e);
> }
> ...
>
>
> It's not as terrible as i initially thought. If the quotable instance is a proxy we instead operate on the proxy's invocation handler.
The later is simple and works.
-------------
PR Review Comment: https://git.openjdk.org/babylon/pull/302#discussion_r1913382135
More information about the babylon-dev
mailing list