teavm icon indicating copy to clipboard operation
teavm copied to clipboard

JSR 310?

Open BrunoEberhard opened this issue 10 years ago • 9 comments

Hi all,

first: great work, the tea vm seems to most promising vm in javascript yet.

My question: When I tried to translate my classes an error was shown because the LocalDate class was not found. I use Java 8. I don't unterstand why your class-lib must copy the whole jre. Why cannot the normal java classes be used?

regards

Bruno

BrunoEberhard avatar Feb 01 '15 13:02 BrunoEberhard

TeaVM runtime has several limitations comparing to JVM:

  1. There is no JNI, as there is no way to run machine code in the browser, or, at least, TeaVM does not aim to support maching code.
  2. There is no reflection. JVM runs natively, so there is separate installation phase for both JVM and application. TeaVM works in the browser, which loads JavaScript on demand, without any installation. Hence, size of the script matters. TeaVM reduces the size of the script by removing unused classes and methods. To figure out, what methods are actually used, TeaVM does static analysis. Reflection kills any static analysis, so I rather killed reflection support.
  3. There is no threading in the browser. WebWorkers are not like threads, they run each in their own address space, similar to OS processes. However, TeaVM is going to obtain its CPS generator, so there will be a chance to implement green threads.
  4. There are no classpath resources. See pt. 2.

Under these circumstances Oracle JDK liraray does not work. It needs deep patching of methods that rely on either reflection, resources, JNI or threading. Furthermore, it needs its own large set of patches for each JDK version.

The second reason is dependency of developer's JVM type and version. Means, you get different generated JavaScript depending on whan JVM it was generated.

As for date and time support. It is often related to locales. Locales mean huge amounts of code and resources. So TeaVM can't even reuse the existing code without dramatical modifications.

konsoletyper avatar Feb 01 '15 16:02 konsoletyper

Many thanks for the prompt answer. I think I unterstand the idea now. So if I really wanna use LocalDate of Java 8 I would have to provide an own implementation of it. Previously I used the backport of JSR 310 in my project. Then I migrated it to java 8. I don't want to go back. How difficult would it be to integrate https://github.com/ThreeTen/threetenbp/ in the class-lib of TeaVM? (Please don't see this as a request, I'm just curious)

BrunoEberhard avatar Feb 01 '15 18:02 BrunoEberhard

Well, I think it won't be too hard, as I've already have experience of backporting Java date/time APIs from Apache Harmony. However, I don't know when I'll have free time. There are so many features to implement.

konsoletyper avatar Feb 01 '15 19:02 konsoletyper

Easy. As I said, I was just curious. Thanks for your help.

BrunoEberhard avatar Feb 01 '15 21:02 BrunoEberhard

I would very much appreciate this feature. What would be required to add such a library to TeaVM?

ooxi avatar Aug 01 '16 08:08 ooxi

Has there been any progress on this feature? Since more and more of my projects are relying on java.time, I'm finding it difficult to re-use my back-end classes on the front-end, which is the main reason why I'm considering to adopt TeaVM.

Thank you for your stunning work!

negora avatar Jan 07 '20 11:01 negora

Hello. Right now I have no plans to support java.time

konsoletyper avatar Jan 09 '20 11:01 konsoletyper

Hello. Right now I have no plans to support java.time

Thank you. It's understandable, given the work load that you've.

In addition to that, I guess that incorporating and adapting the code of java.time from the OpenJDK would conflict with the license of TeaVM, which is Apache License. Because OpenJDK uses GPL with linking exception. Am I right?

negora avatar Jan 10 '20 07:01 negora

I've seen, in the repository, that now there is a branch called java-time with code from the ThreeTen Backport project. The license of that project is BSD 3-clause. I guess that license is compatible with Apache License 2, Right? So, Is there finally a viable plan to incorporate the java.time API into TeaVM? I hope so :-) .

negora avatar Dec 30 '20 23:12 negora