Skip to content

Commit

Permalink
implementing changes from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhea committed Nov 20, 2019
1 parent 67d75e9 commit 1d61ebb
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 253 deletions.
10 changes: 9 additions & 1 deletion bindings/java/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,12 @@ c/build/*
*.dylib
.DS_Store
.gradle
build
build
.classpath
.project
.settings/
java/.classpath
java/.project
java/.settings/
java/bin/
java/hs_err_pid*
135 changes: 43 additions & 92 deletions bindings/java/c/evmc-vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,43 +7,6 @@
#include "evmc-vm.h"
#include "host.h"


JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_test(JNIEnv* jenv, jclass jcls, jobject jbuffer){
struct test_struct{
int one;
long two;
int int1;
int int2;
char three;
long four;
char five[11];
};

struct test_struct *test = (struct test_struct *) (*jenv)->GetDirectBufferAddress(jenv, jbuffer);

struct test_struct *dummy =malloc (sizeof (struct test_struct));
printf("struct: dummy=%p, test=%p\n",dummy,test);
printf("one: dummy=%p, test=%p\n",&dummy->one,&test->one);
printf("two: dummy=%p, test=%p\n",&dummy->two,&test->two);
printf("int1: dummy=%p, test=%p\n",&dummy->int1,&test->int1);
printf("int2: dummy=%p, test=%p\n",&dummy->int2,&test->int2);
printf("three: dummy=%p, test=%p\n",&dummy->three,&test->three);
printf("four: dummy=%p, test=%p\n",&dummy->four, &test->four);
printf("five: dummy=%p, test=%p\n\n",&dummy->five,&test->five);

printf("one=%d\n",test->one);
printf("two=%ld\n",test->two);
printf("int1=%d\n",test->int1);
printf("int2=%d\n",test->int2);
printf("three=%c\n",test->three);
printf("four=%ld\n",test->four);
printf("five=%s\n",test->five);

return 0;


}

JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_init(JNIEnv* jenv, jclass jcls, jstring jfilename)
{
jint rs = (*jenv)->GetJavaVM(jenv, &jvm);
Expand All @@ -55,30 +18,11 @@ JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_init(JNIEnv* jenv, jclass j
evm_handle = evmc_load_and_create(filename, &loader_error);
if (evm_handle == NULL || loader_error != EVMC_LOADER_SUCCESS) {
const char *error_msg = evmc_last_error_msg();
printf("EVMC loading error: %s\n", error_msg);
exit(EXIT_FAILURE);
(*jenv)->ThrowNew(jenv, jcls, error_msg);
return 1;
}
(*jenv)->ReleaseStringUTFChars(jenv, jfilename, filename);

// instantiate the EVMC host interface
host = malloc (sizeof (struct evmc_host_interface));
if (host == NULL) {
exit(EXIT_FAILURE);
}

host->account_exists = account_exists_fn;
host->get_storage = get_storage_fn;
host->set_storage = set_storage_fn;
host->get_storage = get_storage_fn;
host->get_code_size = get_code_size_fn;
host->get_code_hash = get_code_hash_fn;
host->copy_code = copy_code_fn;
host->selfdestruct = selfdestruct_fn;
host->call = call_fn;
host->get_tx_context = get_tx_context_fn;
host->get_block_hash = get_block_hash_fn;
host->emit_log = emit_log_fn;

return 0;
}

Expand All @@ -105,44 +49,51 @@ JNIEXPORT jobject JNICALL Java_org_ethereum_evmc_EvmcVm_execute(JNIEnv *jenv, jc
struct evmc_message *cmsg = (struct evmc_message *) (*jenv)->GetDirectBufferAddress(jenv, jmsg);
const uint8_t * ccode = (uint8_t *) (*jenv)->GetDirectBufferAddress(jenv, jcode);
struct evmc_host_context context = {jcontext_index};
struct evmc_host_interface* host = malloc (sizeof (struct evmc_host_interface));
if (host == NULL) {
(*jenv)->ThrowNew(jenv, jcls, "JNI error: Couldn't instantiate EVMC host interface");
} else {
#ifdef DEBUG
printf("********************before execute*******************\n");

printf("struct: evmc_message=%p\n",cmsg);
printf("sizeof(evmc_message): %lu\n", sizeof(struct evmc_message));
printf("kind=%p\n",&cmsg->kind);
printf("flags=%p\n",&cmsg->flags);
printf("depth=%p\n",&cmsg->depth);
printf("gas=%p\n",&cmsg->gas);
printf("destination=%p\n",&cmsg->destination.bytes);
printf("sender=%p\n",&cmsg->sender.bytes);
printf("input_data=%p\n",&cmsg->input_data);
printf("input_size=%p\n",&cmsg->input_size);
printf("value=%p\n",&cmsg->value.bytes);
printf("create2_salt=%p\n\n",&cmsg->create2_salt.bytes);

printf("kind=%d\n",cmsg->kind);
printf("flags=%d\n",cmsg->flags);
printf("depth=%d\n",cmsg->depth);
printf("gas=%lld\n",cmsg->gas);
printf("destination=%s\n",cmsg->destination.bytes);
printf("sender=%s\n",cmsg->sender.bytes);
printf("input_size=%zu\n",cmsg->input_size);
printf("value=%s\n\n",cmsg->value.bytes);
printf("********************before execute*******************\n");
printf("struct: evmc_message=%p\n",cmsg);
printf("sizeof(evmc_message): %lu\n", sizeof(struct evmc_message));
printf("kind=%p\n",&cmsg->kind);
printf("flags=%p\n",&cmsg->flags);
printf("depth=%p\n",&cmsg->depth);
printf("gas=%p\n",&cmsg->gas);
printf("destination=%p\n",&cmsg->destination.bytes);
printf("sender=%p\n",&cmsg->sender.bytes);
printf("input_data=%p\n",&cmsg->input_data);
printf("input_size=%p\n",&cmsg->input_size);
printf("value=%p\n",&cmsg->value.bytes);
printf("create2_salt=%p\n\n",&cmsg->create2_salt.bytes);

printf("kind=%d\n",cmsg->kind);
printf("flags=%d\n",cmsg->flags);
printf("depth=%d\n",cmsg->depth);
printf("gas=%lld\n",cmsg->gas);
printf("destination=%s\n",cmsg->destination.bytes);
printf("sender=%s\n",cmsg->sender.bytes);
printf("input_size=%zu\n",cmsg->input_size);
printf("value=%s\n\n",cmsg->value.bytes);
#endif
result = evmc_execute(evm_handle,host,&context,jrev,cmsg,ccode,jsize);
jresult = (*jenv)->NewDirectByteBuffer(jenv, (void*) &result, sizeof(struct evmc_result));
init_host(host);
_result = evmc_execute(evm_handle,host,&context,jrev,cmsg,ccode,jsize);
free(host);
jresult = (*jenv)->NewDirectByteBuffer(jenv, (void*) &_result, sizeof(struct evmc_result));
#ifdef DEBUG
printf("********************after execute*******************\n");
printf("sizeof(evmc_result): %lu\n", sizeof(struct evmc_result));
printf("status_code=%p\n",&result.status_code);
printf("gas_left=%p\n",&result.gas_left);
printf("output_data=%p\n\n",&result.output_data);

printf("status_code=%d\n",result.status_code);
printf("gas_left=%llu\n",result.gas_left);
printf("output_data=%s\n\n",result.output_data);
printf("********************after execute*******************\n");
printf("sizeof(evmc_result): %lu\n", sizeof(struct evmc_result));
printf("status_code=%p\n",&_result.status_code);
printf("gas_left=%p\n",&_result.gas_left);
printf("output_data=%p\n\n",&_result.output_data);

printf("status_code=%d\n",_result.status_code);
printf("gas_left=%llu\n",_result.gas_left);
printf("output_data=%s\n\n",_result.output_data);
#endif
}
return jresult;
}

Expand Down
3 changes: 0 additions & 3 deletions bindings/java/c/evmc-vm.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class org_ethereum_evmc_EvmcVm */

Expand All @@ -8,8 +7,6 @@
extern "C" {
#endif

JNIEXPORT jint JNICALL Java_org_ethereum_evmc_EvmcVm_test
(JNIEnv *, jclass, jobject);
/*
* Class: org_ethereum_evmc_EvmcVm
* Method: init
Expand Down
Loading

0 comments on commit 1d61ebb

Please sign in to comment.