Skip to content

ClassNotFoundException MemoryAddress with jdk-19 #212

Closed

Description

@metasoarous

I'm trying out libpython-clj 2.018 on JDK 19, and I'm getting the following error, both the first time I try to initialize, and when attempting to require libpython-clj2.require:

java.lang.ClassNotFoundException: jdk.incubator.foreign.MemoryAddress

I saw issue #180, which suggested adding :jvm-opts ["--add-modules" "jdk.incubator.foreign" "--enable-native-access=ALL-UNNAMED"] to my deps.edn for JVM versions 17 and up. I may tinker around with the version a bit, but it will require rebuilding docker images, so it would be helpful to know if anyone has any experience using libpython-clj 2 with JDK 19.

Thanks

Activity

  1. jjtolton commented on Sep 1, 2022

    @jjtolton
    Contributor

    Pinging @cnuernber on this one.

  2. cnuernber commented on Sep 1, 2022

    @cnuernber
    Collaborator

    So JDK-18, 19 aren't at this time supported as they both have incompatible changes to the pathway from an integer to a direct buffer.

  3. cnuernber commented on Sep 1, 2022

    @cnuernber
    Collaborator

    Specifically 16, 17, 18, 19 all contain incompatible changes there so I have been avoiding upgrading dtype-next to those versions. At this time only JDK-17 is supported beyond JDK-11.

  4. metasoarous commented on Sep 2, 2022

    @metasoarous
    Author

    Got it 👍 Thanks @cnuernber!

    I don't have a strong reason for using any particular JDK version, so happy to stick with JDK 17 for now. It's too bad that we're having to fuss over platform "changes" though. In theory, if someone were motivated, could newer versions be supported?

    Thanks!

  5. cnuernber commented on Sep 2, 2022

    @cnuernber
    Collaborator

    Of course. Its just work - scanning the api changes and fixing dtype-next.

  6. metasoarous commented on Sep 2, 2022

    @metasoarous
    Author

    I switched to JDK 17, and am seeing the same behavior as before.

    For context, I'm pretty sure libpythonclj is finding the correct python installation. And functions like py/->python works. But others do not (such as py/as-python and py/->jvm).

    I have a pretty minimal reproduction of this in a Docker container at https://github.com/metasoarous/libpython-require-error. Please let me know if you see anything obviously wrong there, or have hints about what I should be looking for.

    Thanks again

  7. jjtolton commented on Sep 2, 2022

    @jjtolton
    Contributor

    @metasoarous I see your issue -- and raise you an issue! metasoarous/libpython-require-error#1

  8. metasoarous commented on Sep 2, 2022

    @metasoarous
    Author

    Thanks @jjtolton; That should be resolved now. Please let me know if it gets you to up the issue stack :-)

  9. jjtolton commented on Sep 2, 2022

    @jjtolton
    Contributor

    Much appreciated. I'll dive in shortly!

  10. cnuernber commented on Sep 3, 2022

    @cnuernber
    Collaborator

    One thing I want to note is that to my knowledge :jvm-opts only works in an alias. A top-level :jvm-opts is silently ignored. So I think the example deps.edn needs an alias with it in it and the dockerfile's cmd needs to be updated to include that alias.

    As noted in the other issue if you don't see exactly this warning:

    WARNING: Using incubator modules: jdk.incubator.foreign

    Then you have not loaded the module.

  11. jjtolton commented on Sep 3, 2022

    @jjtolton
    Contributor

    @metasoarous , I reconfigured your deps.edn per @cnuernber 's instructions.

    Current file:

      {:paths ["src"]
     :deps {org.clojure/clojure {:mvn/version "1.11.1"}
            techascent/tech.ml.dataset {:mvn/version "6.093"}
            ;techascent/tech.ml.dataset {:mvn/version "6.086"
                                        ;:exclusions [org.slf4j/slf4j-api]}
            org.bytedeco/mkl-platform-redist {:mvn/version "2020.1-1.5.3"}
            clj-python/libpython-clj {:mvn/version "2.018"}
            cider/cider-nrepl {:mvn/version "0.28.5"}
            com.taoensso/timbre {:mvn/version "5.2.1"}
            ch.qos.logback/logback-classic {:mvn/version "1.1.3"}}
     :aliases {:opts {:jvm-opts ["--add-modules" "jdk.incubator.foreign"
                           "--enable-native-access=ALL-UNNAMED"]}}}

    I now get a different error, but still not working. Note:

    root@802025a3b951:/app# java -version
    openjdk version "17.0.2" 2022-01-18
    OpenJDK Runtime Environment (build 17.0.2+8-86)
    OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

    New error:

    root@802025a3b951:/app# clj -A:opts -m libpython-test.test
    WARNING: Implicit use of clojure.main with options is deprecated, use -M
    WARNING: Using incubator modules: jdk.incubator.foreign
    WARNING: abs already refers to: #'clojure.core/abs in namespace: tech.v3.datatype.functional-api, being replaced by: #'tech.v3.datatype.functional-api/abs
    WARNING: infinite? already refers to: #'clojure.core/infinite? in namespace: tech.v3.datatype.functional-api, being replaced by: #'tech.v3.datatype.functional-api/infinite?
    WARNING: abs already refers to: #'clojure.core/abs in namespace: tech.v3.datatype.functional, being replaced by: #'tech.v3.datatype.functional/abs
    WARNING: infinite? already refers to: #'clojure.core/infinite? in namespace: tech.v3.datatype.functional, being replaced by: #'tech.v3.datatype.functional/infinite?
    20:15:39.461 [main] INFO  libpython-clj2.python.info - Detecting startup info
    20:15:39.502 [main] INFO  libpython-clj2.python - Startup info {:lib-version "3.9", :java-library-path-addendum "/usr/lib", :exec-prefix "/usr", :executable "/usr/bin/python3", :libnames ("python3.9m" "python3.9"), :prefix "/usr", :base-prefix "/usr", :libname "python3.9m", :base-exec-prefix "/usr", :python-home "/usr", :version [3 9 2], :platform "linux"}
    20:15:39.502 [main] INFO  libpython-clj2.python - Prefixing java library path: /usr/lib
    20:15:39.577 [main] INFO  libpython-clj2.python - Loading python library: python3.9
    20:15:40.095 [main] DEBUG libpython-clj2.python.ffi - Initializing Python C Layer
    20:15:40.098 [tech.resource.gc ref thread] INFO  tech.v3.resource.gc - Reference thread starting
    20:15:40.100 [main] DEBUG libpython-clj2.python.ffi - Python Home: /usr
    20:15:40.124 [main] INFO  tech.v3.datatype.nio-buffer - Unable to find direct buffer constructor -
    falling back to jdk16 memory model.
    :OK
    Execution error (NullPointerException) at clojure.main/main (main.java:40).
    Cannot invoke "clojure.lang.IFn.applyTo(clojure.lang.ISeq)" because "f" is null
    
    Full report at:
    /tmp/clojure-7296416279702110182.edn
  12. jjtolton commented on Sep 3, 2022

    @jjtolton
    Contributor

    Hopefully this is a more tractable error?

  13. jjtolton commented on Sep 3, 2022

    @jjtolton
    Contributor

    I think to rule out installation issues, I will try to merge the example Dockerfile with the libpython-clj example Dockerfile to try to rule out installation/version issues.

  14. jjtolton commented on Sep 3, 2022

    @jjtolton
    Contributor

    @metasoarous not sure if this solves the initial problem or not, but I put in a PR to your repo so that at least you have a minimal working setup: metasoarous/libpython-require-error#2

  15. metasoarous commented on Sep 3, 2022

    @metasoarous
    Author

    @cnuernber D'oh! I did not in fact realize that this is a constraint with :jvm-opts. Not clear to me why that's not possible but 🤷 Thanks for pointing out.

    @jjtolton Thank you for digging in! As mentioned in #213, I was able to get baseline functionality working by starting FROM clojure:openjdk-8-tools-deps, which I think is the same version used in the libpython-clj example Dockerfile. I may be fine continuing to use that, which would at least remove any immediate pressure for me, but it would still be nice to sort out connecting to jdk-17 if possible. (PS I had jdk-11 working at one point, but it stopped building some of the python pieces, presumably because the dockerfiles on dockerhub were updated with some weird environmental artifact 🤷)

    Thanks again!

  16. jjtolton commented on Sep 3, 2022

    @jjtolton
    Contributor

    No problem, @metasoarous. Will tinker around later and see if I can a Dockerfile for JDK-17 going. Hopefully this gives you enough for now.

  17. metasoarous commented on Sep 4, 2022

    @metasoarous
    Author

    First off, just wanted to confirm @cnuernber's suspicion that I wasn't using :jdk-opts properly. Now that I've done that, at least jdk-17 works. I'm happy to stick with that for a good while.

    It's up to you whether you want to leave this issue open to track jdk-19 support, in case someone is inspired to work on it. I think it would be great for beginner friendliness to the ecosystem if folks aren't having to worry about JDK version so much. Trying to at least support the LTS versions is probably a pretty tenable path forward if you want to keep things simple.

    Regardless, I think the README could be made a bit clearer regarding which versions are supported. I'm happy to submit an issue &/or PR for that if you agree.

    Thanks again

  18. jjtolton commented on Sep 4, 2022

    @jjtolton
    Contributor
  19. jjtolton commented on Sep 5, 2022

    @jjtolton
    Contributor

    @metasoarous set a PR for a working reference copy with JDK-17

  20. cnuernber commented on Jan 6, 2023

    @cnuernber
    Collaborator

    2.023 and dtype-next version 10.000-beta-18 FIX THIS ISSUE :-)

  21. metasoarous commented on Jan 6, 2023

    @metasoarous
    Author

    @cnuernber AMAZING! Thank you kindly for all your work!

  22. AlexAti commented on Apr 10, 2023

    @AlexAti

    Hello, just a note for people reaching for a problem similar to mine and end up here, in case it saves someone's time: Java 20 no longer has idk.incubator.foreign as a module, so your programs might have broken if you autoupdated your openjdk version (brew did this to me automatically luckily there's still openjdk@17).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions