30
30
import org .graalvm .collections .EconomicMap ;
31
31
32
32
import com .oracle .svm .hosted .webimage .codegen .JSCodeGenTool ;
33
- import com .oracle .svm .hosted .webimage .js .JSStaticFieldDefinition ;
34
33
import com .oracle .svm .hosted .webimage .js .JSStaticMethodDefinition ;
34
+ import com .oracle .svm .util .ReflectionUtil ;
35
35
import com .oracle .svm .webimage .longemulation .Long64 ;
36
36
37
37
import jdk .graal .compiler .core .common .calc .FloatConvert ;
@@ -61,7 +61,6 @@ public class Long64Lowerer {
61
61
public static final long JS_MAX_EXACT_INT53 = 9007199254740991L ;
62
62
public static final long JS_MIN_EXACT_INT53 = -9007199254740991L ;
63
63
private static final EconomicMap <Method , JSStaticMethodDefinition > staticJSMethodCache = EconomicMap .create ();
64
- private static final EconomicMap <Field , JSStaticFieldDefinition > staticJSFieldCache = EconomicMap .create ();
65
64
66
65
public static JSStaticMethodDefinition getJSStaticMethodDefinition (Method method , JSCodeGenTool jsLTools ) {
67
66
if (staticJSMethodCache .containsKey (method )) {
@@ -74,45 +73,21 @@ public static JSStaticMethodDefinition getJSStaticMethodDefinition(Method method
74
73
}
75
74
}
76
75
77
- public static JSStaticFieldDefinition getJSStaticFieldDefinition (Field field , JSCodeGenTool jsLTools ) {
78
- if (staticJSFieldCache .containsKey (field )) {
79
- return staticJSFieldCache .get (field );
80
- } else {
81
- ResolvedJavaField f = jsLTools .getProviders ().getMetaAccess ().lookupJavaField (field );
82
- JSStaticFieldDefinition jsStaticFieldDefinition = new JSStaticFieldDefinition (f );
83
- staticJSFieldCache .put (field , jsStaticFieldDefinition );
84
- return jsStaticFieldDefinition ;
85
- }
86
- }
87
-
88
76
public static void lowerFromConstant (Constant c , JSCodeGenTool jsLTools ) {
89
77
assert c instanceof PrimitiveConstant : c ;
90
78
long longVal = ((PrimitiveConstant ) c ).asLong ();
91
79
92
- Method m ;
93
80
if (longVal == 0 ) {
94
- try {
95
- Field f = Long64 .class .getField ("LongZero" );
96
- JSStaticFieldDefinition constantDefinition = Long64Lowerer .getJSStaticFieldDefinition (f , jsLTools );
97
- constantDefinition .emitAccess (jsLTools );
98
- } catch (NoSuchFieldException e ) {
99
- throw GraalError .shouldNotReachHere (e ); // ExcludeFromJacocoGeneratedReport
100
- }
81
+ Field longZeroField = ReflectionUtil .lookupField (Long64 .class , "LongZero" );
82
+ ResolvedJavaField resolvedField = jsLTools .getProviders ().getMetaAccess ().lookupJavaField (longZeroField );
83
+ jsLTools .genStaticField (resolvedField );
101
84
} else if (Integer .MIN_VALUE <= longVal && longVal <= Integer .MAX_VALUE ) {
102
- try {
103
- m = Long64 .class .getMethod ("fromInt" , int .class );
104
- } catch (NoSuchMethodException e ) {
105
- throw GraalError .shouldNotReachHere (e ); // ExcludeFromJacocoGeneratedReport
106
- }
85
+ Method m = ReflectionUtil .lookupMethod (Long64 .class , "fromInt" , int .class );
107
86
getJSStaticMethodDefinition (m , jsLTools ).emitCall (jsLTools , Emitter .of ((int ) longVal ));
108
87
} else {
109
88
int low = (int ) longVal ;
110
89
int high = (int ) (longVal >> 32 );
111
- try {
112
- m = Long64 .class .getMethod ("fromTwoInt" , int .class , int .class );
113
- } catch (NoSuchMethodException e ) {
114
- throw GraalError .shouldNotReachHere (e ); // ExcludeFromJacocoGeneratedReport
115
- }
90
+ Method m = ReflectionUtil .lookupMethod (Long64 .class , "fromTwoInt" , int .class , int .class );
116
91
getJSStaticMethodDefinition (m , jsLTools ).emitCall (jsLTools , Emitter .of (low ), Emitter .of (high ));
117
92
}
118
93
}
0 commit comments