Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit 1d61ebb

Browse files
committed
implementing changes from code review
1 parent 67d75e9 commit 1d61ebb

File tree

12 files changed

+272
-253
lines changed

12 files changed

+272
-253
lines changed

bindings/java/.gitignore

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,12 @@ c/build/*
77
*.dylib
88
.DS_Store
99
.gradle
10-
build
10+
build
11+
.classpath
12+
.project
13+
.settings/
14+
java/.classpath
15+
java/.project
16+
java/.settings/
17+
java/bin/
18+
java/hs_err_pid*

bindings/java/c/evmc-vm.c

Lines changed: 43 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -7,43 +7,6 @@
77
#include "evmc-vm.h"
88
#include "host.h"
99

10-
11-
JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_test(JNIEnv* jenv, jclass jcls, jobject jbuffer){
12-
struct test_struct{
13-
int one;
14-
long two;
15-
int int1;
16-
int int2;
17-
char three;
18-
long four;
19-
char five[11];
20-
};
21-
22-
struct test_struct *test = (struct test_struct *) (*jenv)->GetDirectBufferAddress(jenv, jbuffer);
23-
24-
struct test_struct *dummy =malloc (sizeof (struct test_struct));
25-
printf("struct: dummy=%p, test=%p\n",dummy,test);
26-
printf("one: dummy=%p, test=%p\n",&dummy->one,&test->one);
27-
printf("two: dummy=%p, test=%p\n",&dummy->two,&test->two);
28-
printf("int1: dummy=%p, test=%p\n",&dummy->int1,&test->int1);
29-
printf("int2: dummy=%p, test=%p\n",&dummy->int2,&test->int2);
30-
printf("three: dummy=%p, test=%p\n",&dummy->three,&test->three);
31-
printf("four: dummy=%p, test=%p\n",&dummy->four, &test->four);
32-
printf("five: dummy=%p, test=%p\n\n",&dummy->five,&test->five);
33-
34-
printf("one=%d\n",test->one);
35-
printf("two=%ld\n",test->two);
36-
printf("int1=%d\n",test->int1);
37-
printf("int2=%d\n",test->int2);
38-
printf("three=%c\n",test->three);
39-
printf("four=%ld\n",test->four);
40-
printf("five=%s\n",test->five);
41-
42-
return 0;
43-
44-
45-
}
46-
4710
JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_init(JNIEnv* jenv, jclass jcls, jstring jfilename)
4811
{
4912
jint rs = (*jenv)->GetJavaVM(jenv, &jvm);
@@ -55,30 +18,11 @@ JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_init(JNIEnv* jenv, jclass j
5518
evm_handle = evmc_load_and_create(filename, &loader_error);
5619
if (evm_handle == NULL || loader_error != EVMC_LOADER_SUCCESS) {
5720
const char *error_msg = evmc_last_error_msg();
58-
printf("EVMC loading error: %s\n", error_msg);
59-
exit(EXIT_FAILURE);
21+
(*jenv)->ThrowNew(jenv, jcls, error_msg);
22+
return 1;
6023
}
6124
(*jenv)->ReleaseStringUTFChars(jenv, jfilename, filename);
6225

63-
// instantiate the EVMC host interface
64-
host = malloc (sizeof (struct evmc_host_interface));
65-
if (host == NULL) {
66-
exit(EXIT_FAILURE);
67-
}
68-
69-
host->account_exists = account_exists_fn;
70-
host->get_storage = get_storage_fn;
71-
host->set_storage = set_storage_fn;
72-
host->get_storage = get_storage_fn;
73-
host->get_code_size = get_code_size_fn;
74-
host->get_code_hash = get_code_hash_fn;
75-
host->copy_code = copy_code_fn;
76-
host->selfdestruct = selfdestruct_fn;
77-
host->call = call_fn;
78-
host->get_tx_context = get_tx_context_fn;
79-
host->get_block_hash = get_block_hash_fn;
80-
host->emit_log = emit_log_fn;
81-
8226
return 0;
8327
}
8428

@@ -105,44 +49,51 @@ JNIEXPORT jobject JNICALL Java_org_ethereum_evmc_EvmcVm_execute(JNIEnv *jenv, jc
10549
struct evmc_message *cmsg = (struct evmc_message *) (*jenv)->GetDirectBufferAddress(jenv, jmsg);
10650
const uint8_t * ccode = (uint8_t *) (*jenv)->GetDirectBufferAddress(jenv, jcode);
10751
struct evmc_host_context context = {jcontext_index};
52+
struct evmc_host_interface* host = malloc (sizeof (struct evmc_host_interface));
53+
if (host == NULL) {
54+
(*jenv)->ThrowNew(jenv, jcls, "JNI error: Couldn't instantiate EVMC host interface");
55+
} else {
10856
#ifdef DEBUG
109-
printf("********************before execute*******************\n");
110-
111-
printf("struct: evmc_message=%p\n",cmsg);
112-
printf("sizeof(evmc_message): %lu\n", sizeof(struct evmc_message));
113-
printf("kind=%p\n",&cmsg->kind);
114-
printf("flags=%p\n",&cmsg->flags);
115-
printf("depth=%p\n",&cmsg->depth);
116-
printf("gas=%p\n",&cmsg->gas);
117-
printf("destination=%p\n",&cmsg->destination.bytes);
118-
printf("sender=%p\n",&cmsg->sender.bytes);
119-
printf("input_data=%p\n",&cmsg->input_data);
120-
printf("input_size=%p\n",&cmsg->input_size);
121-
printf("value=%p\n",&cmsg->value.bytes);
122-
printf("create2_salt=%p\n\n",&cmsg->create2_salt.bytes);
123-
124-
printf("kind=%d\n",cmsg->kind);
125-
printf("flags=%d\n",cmsg->flags);
126-
printf("depth=%d\n",cmsg->depth);
127-
printf("gas=%lld\n",cmsg->gas);
128-
printf("destination=%s\n",cmsg->destination.bytes);
129-
printf("sender=%s\n",cmsg->sender.bytes);
130-
printf("input_size=%zu\n",cmsg->input_size);
131-
printf("value=%s\n\n",cmsg->value.bytes);
57+
printf("********************before execute*******************\n");
58+
59+
printf("struct: evmc_message=%p\n",cmsg);
60+
printf("sizeof(evmc_message): %lu\n", sizeof(struct evmc_message));
61+
printf("kind=%p\n",&cmsg->kind);
62+
printf("flags=%p\n",&cmsg->flags);
63+
printf("depth=%p\n",&cmsg->depth);
64+
printf("gas=%p\n",&cmsg->gas);
65+
printf("destination=%p\n",&cmsg->destination.bytes);
66+
printf("sender=%p\n",&cmsg->sender.bytes);
67+
printf("input_data=%p\n",&cmsg->input_data);
68+
printf("input_size=%p\n",&cmsg->input_size);
69+
printf("value=%p\n",&cmsg->value.bytes);
70+
printf("create2_salt=%p\n\n",&cmsg->create2_salt.bytes);
71+
72+
printf("kind=%d\n",cmsg->kind);
73+
printf("flags=%d\n",cmsg->flags);
74+
printf("depth=%d\n",cmsg->depth);
75+
printf("gas=%lld\n",cmsg->gas);
76+
printf("destination=%s\n",cmsg->destination.bytes);
77+
printf("sender=%s\n",cmsg->sender.bytes);
78+
printf("input_size=%zu\n",cmsg->input_size);
79+
printf("value=%s\n\n",cmsg->value.bytes);
13280
#endif
133-
result = evmc_execute(evm_handle,host,&context,jrev,cmsg,ccode,jsize);
134-
jresult = (*jenv)->NewDirectByteBuffer(jenv, (void*) &result, sizeof(struct evmc_result));
81+
init_host(host);
82+
_result = evmc_execute(evm_handle,host,&context,jrev,cmsg,ccode,jsize);
83+
free(host);
84+
jresult = (*jenv)->NewDirectByteBuffer(jenv, (void*) &_result, sizeof(struct evmc_result));
13585
#ifdef DEBUG
136-
printf("********************after execute*******************\n");
137-
printf("sizeof(evmc_result): %lu\n", sizeof(struct evmc_result));
138-
printf("status_code=%p\n",&result.status_code);
139-
printf("gas_left=%p\n",&result.gas_left);
140-
printf("output_data=%p\n\n",&result.output_data);
141-
142-
printf("status_code=%d\n",result.status_code);
143-
printf("gas_left=%llu\n",result.gas_left);
144-
printf("output_data=%s\n\n",result.output_data);
86+
printf("********************after execute*******************\n");
87+
printf("sizeof(evmc_result): %lu\n", sizeof(struct evmc_result));
88+
printf("status_code=%p\n",&_result.status_code);
89+
printf("gas_left=%p\n",&_result.gas_left);
90+
printf("output_data=%p\n\n",&_result.output_data);
91+
92+
printf("status_code=%d\n",_result.status_code);
93+
printf("gas_left=%llu\n",_result.gas_left);
94+
printf("output_data=%s\n\n",_result.output_data);
14595
#endif
96+
}
14697
return jresult;
14798
}
14899

bindings/java/c/evmc-vm.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* DO NOT EDIT THIS FILE - it is machine generated */
21
#include <jni.h>
32
/* Header for class org_ethereum_evmc_EvmcVm */
43

@@ -8,8 +7,6 @@
87
extern "C" {
98
#endif
109

11-
JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_test
12-
(JNIEnv *, jclass, jobject);
1310
/*
1411
* Class: org_ethereum_evmc_EvmcVm
1512
* Method: init

0 commit comments

Comments
 (0)