@@ -78,14 +78,27 @@ JNIEXPORT void JNICALL Java_org_ethereum_evmc_EvmcVm_destroy(JNIEnv* jenv,
78
78
evmc_destroy (evm );
79
79
}
80
80
81
- JNIEXPORT void JNICALL Java_org_ethereum_evmc_EvmcVm_execute (JNIEnv * jenv ,
82
- jclass jcls ,
83
- jobject jevm ,
84
- jobject jcontext ,
85
- jint jrev ,
86
- jobject jmsg ,
87
- jobject jcode ,
88
- jobject jresult )
81
+ static jobject AllocateDirect (JNIEnv * jenv , size_t capacity )
82
+ {
83
+ const char java_class_name [] = "java/nio/ByteBuffer" ;
84
+ const char java_method_name [] = "allocateDirect" ;
85
+ const char java_method_signature [] = "(I)Ljava/nio/ByteBuffer;" ;
86
+
87
+ jclass jcls = (* jenv )-> FindClass (jenv , java_class_name );
88
+ assert (jcls != NULL );
89
+ jmethodID method =
90
+ (* jenv )-> GetStaticMethodID (jenv , jcls , java_method_name , java_method_signature );
91
+ assert (method != NULL );
92
+ return (* jenv )-> CallStaticObjectMethod (jenv , jcls , method , capacity );
93
+ }
94
+
95
+ JNIEXPORT jobject JNICALL Java_org_ethereum_evmc_EvmcVm_execute (JNIEnv * jenv ,
96
+ jclass jcls ,
97
+ jobject jevm ,
98
+ jobject jcontext ,
99
+ jint jrev ,
100
+ jobject jmsg ,
101
+ jobject jcode )
89
102
{
90
103
(void )jcls ;
91
104
struct evmc_message * msg = (struct evmc_message * )(* jenv )-> GetDirectBufferAddress (jenv , jmsg );
@@ -95,11 +108,14 @@ JNIEXPORT void JNICALL Java_org_ethereum_evmc_EvmcVm_execute(JNIEnv* jenv,
95
108
struct evmc_vm * evm = (struct evmc_vm * )(* jenv )-> GetDirectBufferAddress (jenv , jevm );
96
109
assert (evm != NULL );
97
110
const struct evmc_host_interface * host = evmc_java_get_host_interface ();
111
+ jobject jresult = AllocateDirect (jenv , sizeof (struct evmc_result ));
112
+ assert (jresult != NULL );
98
113
struct evmc_result * result =
99
114
(struct evmc_result * )(* jenv )-> GetDirectBufferAddress (jenv , jresult );
100
115
assert (result != NULL );
101
116
* result = evmc_execute (evm , host , (struct evmc_host_context * )jcontext , (enum evmc_revision )jrev ,
102
117
msg , code , code_size );
118
+ return jresult ;
103
119
}
104
120
105
121
JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_get_1capabilities (JNIEnv * jenv ,
@@ -130,10 +146,3 @@ JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_set_1option(JNIEnv* jenv,
130
146
(* jenv )-> ReleaseStringUTFChars (jenv , jval , value );
131
147
return (jint )option_result ;
132
148
}
133
-
134
- JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_get_1result_1size (JNIEnv * jenv , jclass jcls )
135
- {
136
- (void )jenv ;
137
- (void )jcls ;
138
- return sizeof (struct evmc_result );
139
- }
0 commit comments