了解GWT编译器输出编译器、GWT

2023-09-10 21:33:04 作者:大人少插嘴

我不是JS的开发者,但我想理解的方式在java code转换为JS由GWT编译器确实发现在我们的大型应用程序的内存增加的原因。

I am not JS developer but I am trying to understand the way the java code converted to JS by GWT compiler do find the cause of memory increase in our large application .

一段时间,我看到一些变量,assigened为_,例如

Some time i see some variable with assigened to " _ " for example

_ = com_google_gwt_event_shared_GwtEvent.prototype = new java_lang_Object;

这些类型的任务是在code多处。这是什么意思 ?

These kind of assignments are in many place in the code . What does it means ?

推荐答案

GWT编译器模式的Java类型使用 JavaScript的原型链。该 _ 符号被用作编译器和短JSNI方法全局临时变量。在生成的脚本的顶部范围,你应该看到类似

The GWT compiler models the Java type hierarchy using JavaScript prototype chains. The _ symbol is used as a global temporary variable by the compiler and short JSNI methods. In the top scope of the generated script, you should see something like

// Define the JS constructor(s) for the type
function com___GwtEvent() {}
// Inherit methods from the supertype by prototype chain
_ = com___GwtEvent.prototype = new java_lang_Object;
// Attach polymorphically-dispatched methods to the new type
_.someInstanceMethod = function(a,b,c){.....}
// Static-dispatch methods
function $someOtherMethod(this$static, d, e) {...}

如果你看到有一个这$静态参数,编译器已经推断方法的Java EX pression instance.someOtherMethod( )是不是多态(通过型紧缩可能),避免了中间符号查找的开销在运行时。

Where you see methods that have a this$static parameter, the compiler has deduced that the Java expression instance.someOtherMethod() is not polymorphic (possibly via type-tightening) and avoids the overhead of the intermediate symbol lookup at runtime.