@@ -78,14 +78,27 @@ JNIEXPORT void JNICALL Java_org_ethereum_evmc_EvmcVm_destroy(JNIEnv* jenv,
7878 evmc_destroy (evm );
7979}
8080
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 )
89102{
90103 (void )jcls ;
91104 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,
95108 struct evmc_vm * evm = (struct evmc_vm * )(* jenv )-> GetDirectBufferAddress (jenv , jevm );
96109 assert (evm != NULL );
97110 const struct evmc_host_interface * host = evmc_java_get_host_interface ();
111+ jobject jresult = AllocateDirect (jenv , sizeof (struct evmc_result ));
112+ assert (jresult != NULL );
98113 struct evmc_result * result =
99114 (struct evmc_result * )(* jenv )-> GetDirectBufferAddress (jenv , jresult );
100115 assert (result != NULL );
101116 * result = evmc_execute (evm , host , (struct evmc_host_context * )jcontext , (enum evmc_revision )jrev ,
102117 msg , code , code_size );
118+ return jresult ;
103119}
104120
105121JNIEXPORT 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,
130146 (* jenv )-> ReleaseStringUTFChars (jenv , jval , value );
131147 return (jint )option_result ;
132148}
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