graalvm

meya wudafu 2024-12-24T16:47:32.070319Z

Hey, initially I posted a question here https://clojurians.slack.com/archives/C03S1KBA2/p1734978232607819 (Clojure channel). The solution works for visitMethod on org.objectweb.asm.ClassWriter but trying to apply the same approach for method visitVarInsn on org.objectweb.asm.MethodWriter does not work. Here is my current reflection.json file

[
  {
    "name": "org.objectweb.asm.MethodWriter",
    "methods": [
      {
        "name": "visitVarInsn"
      }
    ]
    "allDeclaredMethods": true
  },
  {
    "name": "org.objectweb.asm.ClassWriter",
    "methods": [
      {
        "name": "visitMethod"
      }
    ]
  }
]
The error is still: > No matching method visitVarInsn found taking 2 args for class org.objectweb.asm.MethodWriter Any advice here? Thanks

borkdude 2024-12-24T16:52:33.011159Z

Why do you have:

"allDeclaredMethods": true
?

borkdude 2024-12-24T16:53:29.239089Z

the method visitVarInsn isn't a declared class on that class, FWIW but it seems like this is unrelated and it should work nonetheless. Do you know where the reflection is being made in the codde?

meya wudafu 2024-12-24T16:53:55.952479Z

just try things from chatGPT 🙂

meya wudafu 2024-12-24T16:54:20.996549Z

let me try find it

meya wudafu 2024-12-24T16:56:29.820189Z

the reference method on asm is here: https://github.com/consulo/objectweb-asm/blob/master/asm/src/main/java/org/objectweb/asm/MethodWriter.java#L909

borkdude 2024-12-24T16:57:05.056239Z

that's not what I was asking for

borkdude 2024-12-24T16:57:15.698289Z

I meant the callsite, sorry for not being clear

meya wudafu 2024-12-24T16:57:34.322529Z

yes, I know, I just point to the method

borkdude 2024-12-24T16:58:45.825019Z

If you control the code, you could try to avoid the reflection in the first place

meya wudafu 2024-12-24T16:59:43.108539Z

you mean, the code where I call the visitVarInsn ?

borkdude 2024-12-24T16:59:48.336199Z

yes

meya wudafu 2024-12-24T17:00:04.584609Z

I call it inside a multimethod

borkdude 2024-12-24T17:00:29.451099Z

Are you familiar with type hints and *warn-on-reflection* ?

meya wudafu 2024-12-24T17:00:45.966419Z

I know about it, but never used,

meya wudafu 2024-12-24T17:00:49.267199Z

I can try

borkdude 2024-12-24T17:01:16.752109Z

That should be your first tool, if you fix all the warnings, then you won't need a reflect config at all probably

meya wudafu 2024-12-24T17:01:35.577599Z

looks perfect, I will try it

borkdude 2024-12-24T17:02:04.585599Z

e.g. here:

(.visit cw Opcodes/V1_8 Opcodes/ACC_PUBLIC class-name nil "java/lang/Object" nil)
you should hint the cw binding with a type hint, e.g.:
(defn foo [^ClassWriter cw])

borkdude 2024-12-24T17:02:41.196879Z

and also put (set! *warn-on-reflection* true) at the top of your namespace

borkdude 2024-12-24T17:02:49.145059Z

if you then evaluate the code, you'll get warnings

meya wudafu 2024-12-24T17:10:15.061999Z

I will try and let you know, thanks a lot for now

borkdude 2024-12-24T17:10:37.219599Z

also check out https://github.com/clj-easy/graal-docs

meya wudafu 2024-12-24T19:41:11.025349Z

Thanks @borkdude using the type hint it works as expected without the reflection.json

👍 1