Compiles Java bytecode to JavaScript, WebAssembly and C
APACHE-2.0 License
Bot releases are visible (Hide)
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.
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).
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.
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.
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)
.
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 propertyVarargs methods of overlay classes now automatically mapped to varargs methods in JS.
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.
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.
String.toLowerCase
/toUpperCase
methods that take Locale
parameterchars
and codePoints
methods in CharSequence
String.format
/Formatter.format
now support more format specifiersMath
methods for arithmetic operations that throw exception on overflowOutputStream.nullOutputStream
SecureRandom
BigInteger.sqrt
WeakHashMap
CopyOnWriteArrayList
ThreadLocal
in green threads@Inherited
annotationsPrintStream
implements Appendable
BufferedReader.lines
methodPromise
(JSPromise
class)@Inherited
annotationsRegistration
to unbind the listener, instead of listenEventName/neglectEventName).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!
Published by konsoletyper 9 months ago
This release contains hotfixes for release 0.9.0
fcmpg
, fcmpl
, dcmpg
, dcmpl
)LinkedHashMap
that could lead to inconsistent state in some casesObjectMethods
emulationInputStreamReader
that lead to infinite loop in some casesSpecial 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.
Published by konsoletyper 12 months ago
This release contains various bugfixes, performance improvements and new emulated Java class library
elements. Among them there are some important improvements worth mentioning.
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.
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.
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.
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.
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.
Double
, Float
and Math
.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.
Some old features were removed from TeaVMTestRunner
:
@WholeClassCompilation
is not deprecated and all test classes compile in single executable by default.@EachTestCompiledSeparately
.New release allows also to suppress tests for separate backends, use @SkipPlatform
and @OnlyPlatform
annotations.
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.
Special thanks to @Ihromant, who contributed lot to this release! Java 21 support is there mostly because of
his efforts.
Also, thanks to:
Published by konsoletyper about 5 years ago
runtime.js
anymore, deprecate Maven and command line options related to runtime.js
generationPublished by konsoletyper over 7 years ago
Published by konsoletyper over 7 years ago
<clinit>
elimination etc)<cinit>
methodsPublished by konsoletyper almost 9 years ago
Published by konsoletyper almost 9 years ago
<clinit>
call in some circumstances (see https://github.com/konsoletyper/teavm/issues/167)a.foo() + a.foo()
, when foo
method has side effects)ClassLoader.getResourceAsStream
by packing specified base64-encoded resources right into produced JS file.Published by konsoletyper almost 9 years ago
Minor bugfixes
Published by konsoletyper almost 9 years ago
Published by konsoletyper over 9 years ago
Class.getDeclaringClass()
in minified mode.Logger.log
with parameters.@Retention
.See https://github.com/konsoletyper/teavm/issues?q=milestone%3A%22Release+0.3.1%22+is%3Aclosed
Published by konsoletyper over 9 years ago
@JSBody
annotation that helps interacting with JavaScript codePublished by konsoletyper almost 10 years ago
StringBuilder.substring(int,int)
JavaScriptBody
annotationprovided
scope.Published by konsoletyper about 10 years ago