Skip to content

Commit

Permalink
Fix some coding style issues, fix doc typo and refine some codes (byt…
Browse files Browse the repository at this point in the history
  • Loading branch information
wenyongh authored Sep 20, 2020
1 parent 7c8ccc7 commit e501a69
Show file tree
Hide file tree
Showing 20 changed files with 155 additions and 227 deletions.
2 changes: 1 addition & 1 deletion core/iwasm/common/wasm_c_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -2202,9 +2202,9 @@ interp_process_export(wasm_store_t *store,

external = wasm_global_as_extern(global);
break;
// TODO:
case EXPORT_KIND_MEMORY:
case EXPORT_KIND_TABLE:
/* TODO: */
break;
default:
goto failed;
Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/common/wasm_c_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ typedef enum runtime_mode_e {
} runtime_mode_e;

struct wasm_engine_t {
// support one store for now
/* support one store for now */
wasm_store_vec_t *stores;
// Interpreter by deault
/* Interpreter by deault */
runtime_mode_e mode;
};

Expand All @@ -49,21 +49,21 @@ struct wasm_valtype_t {

struct wasm_functype_t {
uint32 extern_kind;
// gona to new and delete own
/* gona to new and delete own */
wasm_valtype_vec_t *params;
wasm_valtype_vec_t *results;
};

struct wasm_globaltype_t {
uint32 extern_kind;
// gona to new and delete own
/* gona to new and delete own */
wasm_valtype_t *val_type;
wasm_mutability_t mutability;
};

struct wasm_tabletype_t {
uint32 extern_kind;
// always be WASM_FUNCREF
/* always be WASM_FUNCREF */
wasm_valtype_t *type;
wasm_limits_t *limits;
};
Expand Down
13 changes: 7 additions & 6 deletions core/iwasm/common/wasm_runtime_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ wasm_runtime_destroy_exec_env(WASMExecEnv *exec_env)
wasm_exec_env_destroy(exec_env);
}

#if (WASM_ENABLE_MEMORY_PROFILING != 0) || (WASM_ENABLE_MEMORY_TRACING != 0)
void
wasm_runtime_dump_module_mem_consumption(const WASMModuleCommon *module)
{
Expand Down Expand Up @@ -872,7 +873,6 @@ wasm_runtime_dump_exec_env_mem_consumption(const WASMExecEnv *exec_env)
os_printf(" stack size: %u\n", exec_env->wasm_stack_size);
}

#if WASM_ENABLE_MEMORY_PROFILING != 0
uint32
gc_get_heap_highmark_size(void *heap);

Expand Down Expand Up @@ -951,7 +951,8 @@ wasm_runtime_dump_mem_consumption(WASMExecEnv *exec_env)

os_printf("Total app heap used: %u\n", app_heap_peak_size);
}
#endif
#endif /* end of (WASM_ENABLE_MEMORY_PROFILING != 0)
|| (WASM_ENABLE_MEMORY_TRACING != 0) */

WASMModuleInstanceCommon *
wasm_runtime_get_module_inst(WASMExecEnv *exec_env)
Expand Down Expand Up @@ -2645,7 +2646,7 @@ wasm_runtime_invoke_native_raw(WASMExecEnv *exec_env, void *func_ptr,
}
}

ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;

fail:
if (argv1 != argv_buf)
Expand Down Expand Up @@ -2900,7 +2901,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
}
exec_env->attachment = NULL;

ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;

fail:
if (argv1 != argv_buf)
Expand Down Expand Up @@ -3053,7 +3054,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
}
exec_env->attachment = NULL;

ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;

fail:
if (argv1 != argv_buf)
Expand Down Expand Up @@ -3231,7 +3232,7 @@ wasm_runtime_invoke_native(WASMExecEnv *exec_env, void *func_ptr,
}
exec_env->attachment = NULL;

ret = true;
ret = !wasm_runtime_get_exception(module) ? true : false;
fail:
if (argv1 != argv_buf)
wasm_runtime_free(argv1);
Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ typedef struct WASMGlobalImport {
WASMValue global_data_linked;
#if WASM_ENABLE_MULTI_MODULE != 0
/* imported function pointer after linked */
// TODO: remove if not necessary
/* TODO: remove if not needed */
WASMModule *import_module;
WASMGlobal *import_global_linked;
#endif
Expand Down
1 change: 0 additions & 1 deletion core/iwasm/interpreter/wasm_interp_classic.c
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,6 @@ wasm_interp_call_wasm(WASMModuleInstance *module_inst,
WASMFunctionInstance *function,
uint32 argc, uint32 argv[])
{
// TODO: since module_inst = exec_env->module_inst, shall we remove the 1st arg?
WASMRuntimeFrame *prev_frame = wasm_exec_env_get_cur_frame(exec_env);
WASMInterpFrame *frame, *outs_area;

Expand Down
2 changes: 1 addition & 1 deletion core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -1117,7 +1117,7 @@ wasm_interp_dump_op_count()

#if WASM_ENABLE_LABELS_AS_VALUES != 0

//#define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode
/* #define HANDLE_OP(opcode) HANDLE_##opcode:printf(#opcode"\n");h_##opcode */
#if WASM_ENABLE_OPCODE_COUNTER != 0
#define HANDLE_OP(opcode) HANDLE_##opcode:opcode_table[opcode].count++;h_##opcode
#else
Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -3961,7 +3961,7 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx,
LOG_OP("\nemit_op [%02x]\t", opcode); \
} while (0)

// drop local.get / const / block / loop / end
/* drop local.get / const / block / loop / end */
#define skip_label() do { \
wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
LOG_OP("\ndelete last op\n"); \
Expand Down Expand Up @@ -4334,7 +4334,7 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
if (type == VALUE_TYPE_VOID)
return true;

// only check memory overflow in first traverse
/* only check memory overflow in first traverse */
if (ctx->p_code_compiled == NULL) {
if (!check_offset_push(ctx, error_buf, error_buf_size))
return false;
Expand Down Expand Up @@ -5695,7 +5695,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
+ func->func_type->param_count + idx);
POP_TYPE(ret_type);
#if WASM_ENABLE_FAST_INTERP != 0
// emit the offset after return opcode
/* emit the offset after return opcode */
POP_OFFSET_TYPE(ret_type);
#endif
}
Expand All @@ -5714,7 +5714,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,

read_leb_uint32(p, p_end, func_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, func_idx);
#endif

Expand Down Expand Up @@ -5769,7 +5769,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,

read_leb_uint32(p, p_end, type_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, type_idx);
#endif

Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/interpreter/wasm_mini_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -2890,7 +2890,7 @@ wasm_loader_pop_frame_csp(WASMLoaderContext *ctx,
LOG_OP("\nemit_op [%02x]\t", opcode); \
} while (0)

// drop local.get / const / block / loop / end
/* drop local.get / const / block / loop / end */
#define skip_label() do { \
wasm_loader_emit_backspace(loader_ctx, sizeof(int16)); \
LOG_OP("\ndelete last op\n"); \
Expand Down Expand Up @@ -3264,7 +3264,7 @@ wasm_loader_push_frame_offset(WASMLoaderContext *ctx, uint8 type,
if (type == VALUE_TYPE_VOID)
return true;

// only check memory overflow in first traverse
/* only check memory overflow in first traverse */
if (ctx->p_code_compiled == NULL) {
if (!check_offset_push(ctx, error_buf, error_buf_size))
return false;
Expand Down Expand Up @@ -4525,7 +4525,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
+ func->func_type->param_count + idx);
POP_TYPE(ret_type);
#if WASM_ENABLE_FAST_INTERP != 0
// emit the offset after return opcode
/* emit the offset after return opcode */
POP_OFFSET_TYPE(ret_type);
#endif
}
Expand All @@ -4544,7 +4544,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,

read_leb_uint32(p, p_end, func_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, func_idx);
#endif

Expand Down Expand Up @@ -4592,7 +4592,7 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,

read_leb_uint32(p, p_end, type_idx);
#if WASM_ENABLE_FAST_INTERP != 0
// we need to emit func_idx before arguments
/* we need to emit func_idx before arguments */
emit_uint32(loader_ctx, type_idx);
#endif

Expand Down
10 changes: 5 additions & 5 deletions core/iwasm/interpreter/wasm_runtime.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,15 @@ memories_instantiate(const WASMModule *module,
#if WASM_ENABLE_MULTI_MODULE != 0
WASMMemoryInstance *memory_inst_linked = NULL;
if (import->u.memory.import_module != NULL) {
WASMModuleInstance *module_inst_linked;

LOG_DEBUG("(%s, %s) is a memory of a sub-module",
import->u.memory.module_name,
import->u.memory.field_name);

// TODO: how about native memory ?
WASMModuleInstance *module_inst_linked =
get_sub_module_inst(
module_inst,
import->u.memory.import_module);
module_inst_linked =
get_sub_module_inst(module_inst,
import->u.memory.import_module);
bh_assert(module_inst_linked);

memory_inst_linked =
Expand Down
22 changes: 4 additions & 18 deletions core/shared/platform/common/posix/posix_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,38 +112,24 @@ int os_mutex_destroy(korp_mutex *mutex)
return ret == 0 ? BHT_OK : BHT_ERROR;
}

/* Returned error (EINVAL, EAGAIN and EDEADLK) from
locking the mutex indicates some logic error present in
the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_lock(korp_mutex *mutex)
{
int ret;

assert(mutex);
ret = pthread_mutex_lock(mutex);
if (0 != ret) {
os_printf("vm mutex lock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;

return ret == 0 ? BHT_OK : BHT_ERROR;
}

/* Returned error (EINVAL, EAGAIN and EPERM) from
unlocking the mutex indicates some logic error present
in the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_unlock(korp_mutex *mutex)
{
int ret;

assert(mutex);
ret = pthread_mutex_unlock(mutex);
if (0 != ret) {
os_printf("vm mutex unlock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;

return ret == 0 ? BHT_OK : BHT_ERROR;
}

int os_cond_init(korp_cond *cond)
Expand Down
14 changes: 4 additions & 10 deletions core/shared/platform/nuttx/nuttx_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ os_mutex_lock(korp_mutex *mutex)

assert(mutex);
ret = pthread_mutex_lock(mutex);
if (0 != ret) {
os_printf("vm mutex lock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;

return ret == 0 ? BHT_OK : BHT_ERROR;
}

int
Expand All @@ -50,11 +47,8 @@ os_mutex_unlock(korp_mutex *mutex)

assert(mutex);
ret = pthread_mutex_unlock(mutex);
if (0 != ret) {
os_printf("vm mutex unlock failed (ret=%d)!\n", ret);
exit(-1);
}
return ret;

return ret == 0 ? BHT_OK : BHT_ERROR;
}

uint8 *
Expand Down
8 changes: 0 additions & 8 deletions core/shared/platform/windows/win_thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,19 +61,11 @@ int os_mutex_destroy(korp_mutex *mutex)
return BHT_OK;
}

/* Returned error (EINVAL, EAGAIN and EDEADLK) from
locking the mutex indicates some logic error present in
the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_lock(korp_mutex *mutex)
{
return BHT_ERROR;
}

/* Returned error (EINVAL, EAGAIN and EPERM) from
unlocking the mutex indicates some logic error present
in the program somewhere.
Don't try to recover error for an existing unknown error.*/
int os_mutex_unlock(korp_mutex *mutex)
{
return BHT_OK;
Expand Down
2 changes: 1 addition & 1 deletion doc/build_wamr.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ cmake -DWAMR_BUILD_PLATFORM=linux -DWAMR_BUILD_TARGET=ARM
> Note: by default only platform linux/darwin/android/vxworks 64-bit will enable boundary check with hardware trap in AOT or JIT mode, and the wamrc tool will generate AOT code without boundary check instructions in all 64-bit targets except SGX to improve performance.
#### **Enable memory profiling (Experiment)**
- **WAMR_BUILD_MEMORY_PROFLING**=1/0, default to disable if not set
- **WAMR_BUILD_MEMORY_PROFILING**=1/0, default to disable if not set
> Note: if it is enabled, developer can use API `void wasm_runtime_dump_mem_consumption(wasm_exec_env_t exec_env)` to dump the memory consumption info.
Currently we only profile the memory consumption of module, module_instance and exec_env, the memory consumed by other components such as `wasi-ctx`, `multi-module` and `thread-manager` are not included.

Expand Down
1 change: 1 addition & 0 deletions product-mini/app-samples/hello-world/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ WAMR_DIR=${PWD}/../../..
--sysroot=${WAMR_DIR}/wamr-sdk/app/libc-builtin-sysroot \
-Wl,--allow-undefined-file=${WAMR_DIR}/wamr-sdk/app/libc-builtin-sysroot/share/defined-symbols.txt \
-Wl,--export=main, \
-Wl,--export=__data_end, -Wl,--export=__heap_base \
-Wl,--no-threads,--strip-all,--no-entry \
-nostdlib -o test.wasm *.c
#./jeffdump -o test_wasm.h -n wasm_test_file test.wasm
Loading

0 comments on commit e501a69

Please sign in to comment.