Skip to content

Releases: konsoletyper/teavm

0.10.0

30 Apr 17:30
Compare
Choose a tag to compare

Improvements to native JavaScript interaction

Exporting declarations from Java to JavaScript

This long expected feature is finally delivered by this release. Now TeaVM can not only take standard Java main classes with main methods, but also module classes. Instead of main method, they can declare static methods annotated with @JSExport.
These methods will be exported from generated TeaVM module (or rather as top-level declarations in non-module output).

Additionally, @JSExport annotation can be used to mark methods of classes that should be available in JS. See full documentation in Creating JavaScript modules section.

Generating modules

From this release, TeaVM can produce ES2015 modules. Moreover, there's a new build parameter that allows to specify module type (CommonJS, ES2015, UMD, immediately-invoked function).

Importing constructors

Previously, to declare a constructor for a JS class, you had to define static factory method, annotated with @JSBody and some JS within. Now, it's possible to declare a non-abstract overlay class (should be additionally annotated with @JSClass) with constructors. To instantiate such classes, you can use new syntax, as you used for normal Java classes.

Importing static and top-level methods

Since this release, you can define static native methods of overlay classes without extra annotations. These methods will be automatically mapped to corresponding static JS methods.

You can also put @JSTopLevel annotation on such methods so that they aren't mapped to static methods of containing classes, but to top-level methods.

Support instanceof

Overlay classes now properly support instanceof and casts (in strict mode). Note that instanceof is not available for interfaces (i.e. as previously, always produces true). Support of instanceof can be disabled for classes by applying @JSClass(transparent = true).

Importing declarations from external modules

You can also use @JSModule annotation to import declarations from JS modules. Following cases possible:

  • @JSModule on class – imports class
  • @JSModule and @JSTopLevel – imports function
  • @JSModule, @JSTopLevel and @JSProperty – imports property

Support varargs

Varargs methods of overlay classes now automatically mapped to varargs methods in JS.

Improved string representation

This release has changed the way java.lang.String represented internally. Instead of array of char, java.lang.String now contains field of native JS string. This can improve performance in some cases, most likely in calls to native JS methods. Previously, to convert java.lang.String to and from JS method, a full copy should have been made. Now, TeaVM only wraps/unwraps JS string with java.lang.String implementation, which is much faster.

This also improves debugging experience. Previously, if you open a java.lang.String value in browser dev tools, you had a object, which has a field, which is an object in turn, which wraps UInt16Array. Now, you only have to deal with one level of indirection (object that has a field), and an actual representation is not array of char codes, but JS string, easily readable in dev tools.

ES2015 modules

Since this release, TeaVM generates ES2015 output, not ES5. This allows not only to support ES2015 modules, but reduces output side thanks to arrow function syntax.

Class library emulation

  • String.toLowerCase/toUpperCase methods that take Locale parameter
  • chars and codePoints methods in CharSequence
  • String.format/Formatter.format now support more format specifiers
  • Math methods for arithmetic operations that throw exception on overflow
  • OutputStream.nullOutputStream
  • SecureRandom
  • BigInteger.sqrt
  • WeakHashMap
  • CopyOnWriteArrayList
  • Fair support of ThreadLocal in green threads
  • Support @Inherited annotations
  • PrintStream implements Appendable
  • BufferedReader.lines method

Gradle plugin improvements

  • Improve source file resolution when generating source maps in Gradle
  • Add tasks to start/update and stop development server

Other stuff

  • Overlay class for JS Promise (JSPromise class)
  • Support @Inherited annotations
  • New convention for event registration in standard overlay classes (onEventName returning Registration to unbind the listener, instead of listenEventName/neglectEventName).

Sponsorship

Worth mentioning that TeaVM evolved with the support from its sponsors. If you like this project, you can start donating.

Special thanks to @reportmill and @shannah, our permanent sponsors!

Contributors

0.9.2

08 Jan 18:21
Compare
Choose a tag to compare

This release contains hotfixes for release 0.9.0

  • Fix Maven archetype
  • Fix declaration in IndexedDB API
  • Fixes for wrapping JS values into Java objects
  • Fix issue in optimizing floating-point comparison operations (fcmpg, fcmpl, dcmpg, dcmpl)
    in corner-cases like NaN or negative zero
  • Fix bug in LinkedHashMap that could lead to inconsistent state in some cases
  • Fix boxing/unboxing arguments and return values in method references
  • Widen byte/short to ints in ObjectMethods emulation
  • Fix issue in InputStreamReader that lead to infinite loop in some cases

Special thanks to @SquidDev who contributed commit to this release.

Note that due to mistake version 0.9.1 was published with incorrect content.
Please, ignore it.

0.9.0

24 Oct 17:24
Compare
Choose a tag to compare

This release contains various bugfixes, performance improvements and new emulated Java class library
elements. Among them there are some important improvements worth mentioning.

Java 21 support

Most notable change in this release is support for Java 21 features. This includes support for Java 21 bytecode,
switch pattern matching and sequenced collections.

JavaScript interop

Another important change is JavaScript interop API. First, the gap between Java and JavaScript worlds becomes
more transparent. This means: JS overlay objects (i.e. those which implement JSObject interface)
now behave closer to normal objects. Now it's possible to call their methods, inherited from Object,
like equals, hashCode, toString, getClass and so on. instanceof JSObject can also be used
to distinguish between JavaScript and Java objects, and cast to JSObject will only succeed for JavaScript
objects.

Second, TeaVM starts producing JavaScript modules by wrapping generated code into UMD wrappers.
TeaVM now can generate imports: you can use new @JSBodyImport annotation in addition to @JSBody
to specify calls to routines defined in external modules.

Third, it's now possible to declare parameters and return values of JavaScript methods as Object.
This allows to pass Java objects to JavaScript methods. For example, it's possible to declare Promise
that resolves to Java type. Additionally, some existing JSO APIs were updated to have Object
instead of JSObject in their signature, which in some cases can break existing code (though, it must be
quite easy to fix).

Finally, it's now possible to add properties to Java objects exported to JavaScript.
Now when Java class implements JSO interface, which has methods marked with @JSProperty annotation,
they will work as expected.

Class library

ConcurrentHashMap

This long-awaited feature is at last here. There were codebases that relied on this class and did several
efforts to patch TeaVM to solve this issues. New ConcurrentHashMap implementation is fair implementation,
which works well with TeaVM green threads. In case there are no threads at all, ConcurrentHashMap implementation
will prevent turning Java methods into state machine, so no overhead there.

WeakReference and ReferenceQueue

These classes used to be implemented by C and WebAssembly backends, since both have their own heap.
However, for JavaScript this was not possible until all major browsers started shipping WeakRef API.

Atomic field updaters

AtomicReferenceFieldUpdater used by Kotlin standard library to implement lazy properties.
Instead of patching Kotlin bytecode, TeaVM comes with fair support of three classes:
AtomicReferenceFieldUpdater, AtomicIntegerFieldUpdater and AtomicLongFieldUpdater.
These classes have each two implementation: efficient and generic. Efficient implementation
is only used when constants passed to newUpdater method. Otherwise, generic implementation is used, which
uses reflection under-the-hood, so corresponding fields should be property marked as reflectable.

Other changes

  1. Improvements to number-to-string and string-to-number conversions
    (still some inconsistencies with doubles and floats).
  2. Improvements to support of floating points operations in Double, Float and Math.
  3. Improvements to Streams support.

WebAssembly backend

New release provides major improvements to WebAssembly support. Not only stability is improved,
but very process has changed. From now on WebAssembly tests run as part of each release and preview build.
This was possible to run WebAssembly tests, but some were failing, and when regression occurred,
it was hard to find it. The new version allows to ignore tests for separate backends.
Failing tests were ignored for WebAssembly and remaining tests are supposed to pass on each build.

Additionally, new release introduces better support for DWARF. It's still far from perfect, but
it already works with Google Chrome C++ debugging extension.
Line numbers are generated properly in most cases, variables often point to wrong locations.

Test runner

Some old features were removed from TeaVMTestRunner:

  1. It does not support parallel running anymore. Instead, developer should use JUnit built-in feature
    to run test classes in parallel.
  2. HtmlUnit was also removed.
  3. @WholeClassCompilation is not deprecated and all test classes compile in single executable by default.
    To override this behaviour, use @EachTestCompiledSeparately.

New release allows also to suppress tests for separate backends, use @SkipPlatform and @OnlyPlatform annotations.

Sponsorship

TeaVM now participates in GitHub sponsors. You can support TeaVM not only by contributing code or documentation,
but also send some money to the project.

Special thanks to @reportmill and @shannah, our permanent sponsors! Also, thanks to @aloraps, who
sponsored this particular release.

Contributors

Special thanks to @Ihromant, who contributed lot to this release! Java 21 support is there mostly because of
his efforts.

Also, thanks to:

0.6.0

17 Sep 14:31
Compare
Choose a tag to compare
  • Improve performance and stability of compiler
  • Reduce size of generates JavaScript
  • Support Stream API
  • Generate immediately invoked function to protect global name space from pollution
  • Don't generate runtime.js anymore, deprecate Maven and command line options related to runtime.js generation
  • Drop support of old IE browsers
  • New code server for fast incremental recompilation
  • Add possibility to start separate TeaVM process from Maven
  • Don't report compile-time error when there's possible misuse of async methods
  • Support Java 13
  • Experimental C code generator (Linux and Windows only)

0.5.1

05 Jul 18:35
Compare
Choose a tag to compare
  • Fix build daemon hanging on closing IDEA
  • Add missing files from Unicode CLDR
  • Fix capacity calculation in ArrayList and StringBuilder
  • Fix bugs in source map generation and debugging support in IDEA
  • Fix errors not appearing in IDEA messages window when can't find corresponding location

Release 0.5.0

19 Jun 19:06
Compare
Choose a tag to compare
  • Drop Eclipse support, introduce IntelliJ IDEA support
  • A new metaprogramming API
  • A set of new performance optimizations (inlining, escape analysis/scalar replacement, redundant <clinit> elimination etc)
  • Support for Kotlin and Scala
  • Support html4j 1.4
  • Experimental support for WebAssembly
  • Update to the latest versions of UnicodeData, CLDR and tzdata
  • Support asynchronous <cinit> methods
  • Performance improvements and bugfixes in compiler

Release 0.4.3

31 Dec 06:33
Compare
Choose a tag to compare
  • Fix loop hierarchy recognition in some cases when loop nesting is at least 3
  • Fix bug in base64 resource decoder

Release 0.4.1

30 Nov 17:28
Compare
Choose a tag to compare

Minor bugfixes

Release 0.4.2

26 Dec 12:05
Compare
Choose a tag to compare
  • Fix missing <clinit> call in some circumstances (see #167)
  • When passing non-JS types to JSBody methods, report an error
  • Avoid inlining of JSBody when one of parameters got used more than once (for example, it can cause error with script like a.foo() + a.foo(), when foo method has side effects)
  • Reduce amount of exported JS methods
  • Implement ClassLoader.getResourceAsStream by packing specified base64-encoded resources right into produced JS file.

0.4.0

22 Oct 17:32
Compare
Choose a tag to compare
  • Java 8 lambda support
  • Java 8 function package
  • Big improvements in JSO module: improved JSBody compilation, JSBody inlining, split spec, implementation and API, allow calling Java code from JSBody
  • Html4Java 1.2.3 support
  • Refactor Maven plugin
  • Scala support
  • Builds in CI