-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WASM] Avoid triggering clinit from internal calls in class
This handles basic inner cycles for clinit due to calls to methods. Consider following: ``` class Foo { // initialized in Foo.clinit public static final Foo instance = new Foo(); // Also calls Foo.clinit since it is public public Foo() {} } ``` We essentially have two entry points in the classes that we need to clinit. This introduces a cycle in clinit (clinit call ctor, ctor calls clinit) and we cannot hoist instance to global because it is no longer trivial. This could also happen with following pattern: ``` class Foo { // initialized in Foo.clinit public static final int instance = someHelper(); // Also calls Foo.clinit since it is public public static int someHelper() { ... } } ``` To overcome this problem, when there is a public method that triggers clinit, we can make it private and add a public one that calls clinit. Then re-writing Internal calls go through private one so they don't trigger clinit. Since this only requires local knowledge, it is compatible with modular compilation. PiperOrigin-RevId: 590882728
- Loading branch information
1 parent
893fd3e
commit 71f2c81
Showing
37 changed files
with
869 additions
and
185 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4969,10 +4969,20 @@ | |
(func [email protected] | ||
(result (ref null $bridgemethods.AccidentalOverrideBridge)) | ||
;;@ bridgemethods/BridgeMethod.java:96:6 | ||
(local $$instance (ref null $bridgemethods.AccidentalOverrideBridge)) | ||
(block | ||
;;@ bridgemethods/BridgeMethod.java:96:6 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ bridgemethods/BridgeMethod.java:96:6 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; AccidentalOverrideBridge AccidentalOverrideBridge.$create_$private() | ||
(func [email protected] | ||
(result (ref null $bridgemethods.AccidentalOverrideBridge)) | ||
;;@ bridgemethods/BridgeMethod.java:96:6 | ||
(local $$instance (ref null $bridgemethods.AccidentalOverrideBridge)) | ||
(block | ||
;;@ bridgemethods/BridgeMethod.java:96:6 | ||
(local.set $$instance (struct.new $bridgemethods.AccidentalOverrideBridge (ref.as_non_null (global.get $bridgemethods.AccidentalOverrideBridge.vtable)) (ref.as_non_null (global.get $bridgemethods.AccidentalOverrideBridge.itable)) (i32.const 0))) | ||
;;@ bridgemethods/BridgeMethod.java:96:6 | ||
|
@@ -5002,7 +5012,7 @@ | |
(local.set $this (ref.cast (ref $bridgemethods.AccidentalOverrideBridge) (local.get $this.untyped))) | ||
(block | ||
;;@ bridgemethods/BridgeMethod.java:100:4 | ||
(local.set $g (call $$create__@bridgemethods.AccidentalOverrideBridge )) | ||
(local.set $g (call $$create_$private__@bridgemethods.AccidentalOverrideBridge )) | ||
;;@ bridgemethods/BridgeMethod.java:101:4 | ||
(drop (call_ref $function.m_get__java_lang_String__java_lang_String (ref.as_non_null (local.get $g))(call $function.no.side.effects.$getString_||__java_lang_String (ref.func $$getString_||[email protected]) )(struct.get $bridgemethods.Getter.vtable $m_get__java_lang_String__java_lang_String (ref.cast (ref $bridgemethods.Getter.vtable) (struct.get $itable $slot0 (struct.get $java.lang.Object $itable (local.get $g))))))) | ||
) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -793,10 +793,20 @@ | |
(func [email protected] | ||
(result (ref null $cast.CastGenerics)) | ||
;;@ cast/CastGenerics.java:20:13 | ||
(local $$instance (ref null $cast.CastGenerics)) | ||
(block | ||
;;@ cast/CastGenerics.java:20:13 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ cast/CastGenerics.java:20:13 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; CastGenerics<T, E> CastGenerics.$create_$private() | ||
(func [email protected] | ||
(result (ref null $cast.CastGenerics)) | ||
;;@ cast/CastGenerics.java:20:13 | ||
(local $$instance (ref null $cast.CastGenerics)) | ||
(block | ||
;;@ cast/CastGenerics.java:20:13 | ||
(local.set $$instance (struct.new $cast.CastGenerics (ref.as_non_null (global.get $cast.CastGenerics.vtable)) (ref.as_non_null (global.get $itable.empty)) (i32.const 0) (ref.null $java.lang.Object))) | ||
;;@ cast/CastGenerics.java:20:13 | ||
|
@@ -862,10 +872,10 @@ | |
;;@ cast/CastGenerics.java:50:70 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ cast/CastGenerics.java:51:4 | ||
(local.set $str (ref.cast (ref null $java.lang.String) (struct.get $cast.CastGenerics [email protected] (call $$create__@cast.CastGenerics )))) | ||
(local.set $str (ref.cast (ref null $java.lang.String) (struct.get $cast.CastGenerics [email protected] (call $$create_$private__@cast.CastGenerics )))) | ||
;;@ cast/CastGenerics.java:52:4 | ||
(local.set $str (ref.cast (ref null $java.lang.String) (block (result (ref null $java.lang.Object)) | ||
(local.set $$qualifier (call $$create__@cast.CastGenerics )) | ||
(local.set $$qualifier (call $$create_$private__@cast.CastGenerics )) | ||
(call_ref $function.m_method__java_lang_Object_$pp_cast (ref.as_non_null (local.get $$qualifier))(struct.get $cast.CastGenerics.vtable $m_method__java_lang_Object_$pp_cast (struct.get $cast.CastGenerics $vtable(local.get $$qualifier)))) | ||
))) | ||
;;@ cast/CastGenerics.java:54:4 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,13 +103,23 @@ | |
) | ||
) | ||
|
||
;;; void CastOnArrayInit.fun(Foo<E>... args) | ||
;;; void CastOnArrayInit.fun(Foo<E>... arg0) | ||
(func $m_fun__arrayOf_castonarrayinit_CastOnArrayInit_Foo__void@castonarrayinit.CastOnArrayInit | ||
(param $args (ref null $javaemul.internal.WasmArray.OfObject)) | ||
(param $arg0 (ref null $javaemul.internal.WasmArray.OfObject)) | ||
;;@ castonarrayinit/CastOnArrayInit.java:21:25 | ||
(block | ||
;;@ castonarrayinit/CastOnArrayInit.java:21:45 | ||
;;@ castonarrayinit/CastOnArrayInit.java:21:25 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ castonarrayinit/CastOnArrayInit.java:21:25 | ||
(call $m_fun_$private__arrayOf_castonarrayinit_CastOnArrayInit_Foo__void@castonarrayinit.CastOnArrayInit (local.get $arg0)) | ||
) | ||
) | ||
|
||
;;; void CastOnArrayInit.fun_$private(Foo<E>... args) | ||
(func $m_fun_$private__arrayOf_castonarrayinit_CastOnArrayInit_Foo__void@castonarrayinit.CastOnArrayInit | ||
(param $args (ref null $javaemul.internal.WasmArray.OfObject)) | ||
;;@ castonarrayinit/CastOnArrayInit.java:21:25 | ||
(block | ||
) | ||
) | ||
|
||
|
@@ -126,7 +136,7 @@ | |
;;@ castonarrayinit/CastOnArrayInit.java:25:4 | ||
(local.set $f2 (call [email protected] )) | ||
;;@ castonarrayinit/CastOnArrayInit.java:26:4 | ||
(call $m_fun__arrayOf_castonarrayinit_CastOnArrayInit_Foo__void@castonarrayinit.CastOnArrayInit (call $m_newWithLiteral__arrayOf_java_lang_Object__javaemul_internal_WasmArray_OfObject@javaemul.internal.WasmArray.OfObject (array.new_fixed $java.lang.Object.array (local.get $f1)(local.get $f2)))) | ||
(call $m_fun_$private__arrayOf_castonarrayinit_CastOnArrayInit_Foo__void@castonarrayinit.CastOnArrayInit (call $m_newWithLiteral__arrayOf_java_lang_Object__javaemul_internal_WasmArray_OfObject@javaemul.internal.WasmArray.OfObject (array.new_fixed $java.lang.Object.array (local.get $f1)(local.get $f2)))) | ||
) | ||
) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -342,10 +342,20 @@ | |
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithoutCloneable)) | ||
;;@ cloneable/Cloneables.java:19:22 | ||
(local $$instance (ref null $cloneable.Cloneables.WithoutCloneable)) | ||
(block | ||
;;@ cloneable/Cloneables.java:19:22 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ cloneable/Cloneables.java:19:22 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; WithoutCloneable WithoutCloneable.$create_$private() | ||
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithoutCloneable)) | ||
;;@ cloneable/Cloneables.java:19:22 | ||
(local $$instance (ref null $cloneable.Cloneables.WithoutCloneable)) | ||
(block | ||
;;@ cloneable/Cloneables.java:19:22 | ||
(local.set $$instance (struct.new $cloneable.Cloneables.WithoutCloneable (ref.as_non_null (global.get $cloneable.Cloneables.WithoutCloneable.vtable)) (ref.as_non_null (global.get $itable.empty)) (i32.const 0))) | ||
;;@ cloneable/Cloneables.java:19:22 | ||
|
@@ -375,7 +385,7 @@ | |
(local.set $this (ref.cast (ref $cloneable.Cloneables.WithoutCloneable) (local.get $this.untyped))) | ||
(block | ||
;;@ cloneable/Cloneables.java:23:6 | ||
(return (call $$create__@cloneable.Cloneables.WithoutCloneable )) | ||
(return (call $$create_$private__@cloneable.Cloneables.WithoutCloneable )) | ||
) | ||
) | ||
(elem declare func [email protected]) | ||
|
@@ -443,10 +453,20 @@ | |
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithCloneable)) | ||
;;@ cloneable/Cloneables.java:27:22 | ||
(local $$instance (ref null $cloneable.Cloneables.WithCloneable)) | ||
(block | ||
;;@ cloneable/Cloneables.java:27:22 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ cloneable/Cloneables.java:27:22 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; WithCloneable WithCloneable.$create_$private() | ||
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithCloneable)) | ||
;;@ cloneable/Cloneables.java:27:22 | ||
(local $$instance (ref null $cloneable.Cloneables.WithCloneable)) | ||
(block | ||
;;@ cloneable/Cloneables.java:27:22 | ||
(local.set $$instance (struct.new $cloneable.Cloneables.WithCloneable (ref.as_non_null (global.get $cloneable.Cloneables.WithCloneable.vtable)) (ref.as_non_null (global.get $cloneable.Cloneables.WithCloneable.itable)) (i32.const 0))) | ||
;;@ cloneable/Cloneables.java:27:22 | ||
|
@@ -476,7 +496,7 @@ | |
(local.set $this (ref.cast (ref $cloneable.Cloneables.WithCloneable) (local.get $this.untyped))) | ||
(block | ||
;;@ cloneable/Cloneables.java:31:6 | ||
(return (call $$create__@cloneable.Cloneables.WithCloneable )) | ||
(return (call $$create_$private__@cloneable.Cloneables.WithCloneable )) | ||
) | ||
) | ||
(elem declare func [email protected]) | ||
|
@@ -544,10 +564,20 @@ | |
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithoutCloneableChild)) | ||
;;@ cloneable/Cloneables.java:35:28 | ||
(local $$instance (ref null $cloneable.Cloneables.WithoutCloneableChild)) | ||
(block | ||
;;@ cloneable/Cloneables.java:35:28 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ cloneable/Cloneables.java:35:28 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; WithoutCloneableChild WithoutCloneableChild.$create_$private() | ||
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithoutCloneableChild)) | ||
;;@ cloneable/Cloneables.java:35:28 | ||
(local $$instance (ref null $cloneable.Cloneables.WithoutCloneableChild)) | ||
(block | ||
;;@ cloneable/Cloneables.java:35:28 | ||
(local.set $$instance (struct.new $cloneable.Cloneables.WithoutCloneableChild (ref.as_non_null (global.get $cloneable.Cloneables.WithoutCloneableChild.vtable)) (ref.as_non_null (global.get $itable.empty)) (i32.const 0))) | ||
;;@ cloneable/Cloneables.java:35:28 | ||
|
@@ -577,7 +607,7 @@ | |
(local.set $this (ref.cast (ref $cloneable.Cloneables.WithoutCloneableChild) (local.get $this.untyped))) | ||
(block | ||
;;@ cloneable/Cloneables.java:38:6 | ||
(return (call $$create__@cloneable.Cloneables.WithoutCloneableChild )) | ||
(return (call $$create_$private__@cloneable.Cloneables.WithoutCloneableChild )) | ||
) | ||
) | ||
(elem declare func $m_clone__java_lang_Object@cloneable.Cloneables.WithoutCloneableChild) | ||
|
@@ -645,10 +675,20 @@ | |
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithCloneableChild)) | ||
;;@ cloneable/Cloneables.java:42:28 | ||
(local $$instance (ref null $cloneable.Cloneables.WithCloneableChild)) | ||
(block | ||
;;@ cloneable/Cloneables.java:42:28 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ cloneable/Cloneables.java:42:28 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; WithCloneableChild WithCloneableChild.$create_$private() | ||
(func [email protected] | ||
(result (ref null $cloneable.Cloneables.WithCloneableChild)) | ||
;;@ cloneable/Cloneables.java:42:28 | ||
(local $$instance (ref null $cloneable.Cloneables.WithCloneableChild)) | ||
(block | ||
;;@ cloneable/Cloneables.java:42:28 | ||
(local.set $$instance (struct.new $cloneable.Cloneables.WithCloneableChild (ref.as_non_null (global.get $cloneable.Cloneables.WithCloneableChild.vtable)) (ref.as_non_null (global.get $cloneable.Cloneables.WithCloneableChild.itable)) (i32.const 0))) | ||
;;@ cloneable/Cloneables.java:42:28 | ||
|
@@ -678,7 +718,7 @@ | |
(local.set $this (ref.cast (ref $cloneable.Cloneables.WithCloneableChild) (local.get $this.untyped))) | ||
(block | ||
;;@ cloneable/Cloneables.java:45:6 | ||
(return (call $$create__@cloneable.Cloneables.WithCloneableChild )) | ||
(return (call $$create_$private__@cloneable.Cloneables.WithCloneableChild )) | ||
) | ||
) | ||
(elem declare func $m_clone__java_lang_Object@cloneable.Cloneables.WithCloneableChild) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -865,10 +865,20 @@ | |
(func [email protected] | ||
(result (ref null $collisions.T)) | ||
;;@ collisions/goog.java:74:6 | ||
(local $$instance (ref null $collisions.T)) | ||
(block | ||
;;@ collisions/goog.java:74:6 | ||
(call $$clinit__void_<once>[email protected] ) | ||
;;@ collisions/goog.java:74:6 | ||
(return (call [email protected] )) | ||
) | ||
) | ||
|
||
;;; T<T> T.$create_$private() | ||
(func [email protected] | ||
(result (ref null $collisions.T)) | ||
;;@ collisions/goog.java:74:6 | ||
(local $$instance (ref null $collisions.T)) | ||
(block | ||
;;@ collisions/goog.java:74:6 | ||
(local.set $$instance (struct.new $collisions.T (ref.as_non_null (global.get $collisions.T.vtable)) (ref.as_non_null (global.get $itable.empty)) (i32.const 0))) | ||
;;@ collisions/goog.java:74:6 | ||
|
@@ -916,7 +926,7 @@ | |
(block | ||
;;@ collisions/goog.java:80:4 | ||
(local.set $t (block (result (ref null $java.lang.Number)) | ||
(local.set $$qualifier (call $$create__@collisions.T )) | ||
(local.set $$qualifier (call $$create_$private__@collisions.T )) | ||
(call_ref $function.m_m__java_lang_Number_$pp_collisions (ref.as_non_null (local.get $$qualifier))(struct.get $collisions.T.vtable $m_m__java_lang_Number_$pp_collisions (struct.get $collisions.T $vtable(local.get $$qualifier)))) | ||
)) | ||
;;@ collisions/goog.java:81:4 | ||
|
Oops, something went wrong.