Skip to content

Commit 004b913

Browse files
committed
Merge branch main into dev/gc_refactor
2 parents dcde455 + 529fa9d commit 004b913

27 files changed

+426
-438
lines changed

.github/workflows/compilation_on_android_ubuntu.yml

-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ jobs:
146146
"-DWAMR_BUILD_SIMD=1",
147147
"-DWAMR_BUILD_TAIL_CALL=1",
148148
"-DWAMR_DISABLE_HW_BOUND_CHECK=1",
149-
"-DWAMR_ENABLE_SHARED_MEMORY_MMAP=1",
150149
]
151150
os: [ubuntu-22.04]
152151
platform: [android, linux]

.github/workflows/compilation_on_macos.yml

+40-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright (C) 2019 Intel Corporation. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

4-
name: compilation on macos-latest
4+
name: compilation on macos
55

66
on:
77
# will be triggered on PR events
@@ -55,20 +55,25 @@ env:
5555
LLVM_EAGER_JIT_BUILD_OPTIONS: "-DWAMR_BUILD_AOT=1 -DWAMR_BUILD_FAST_INTERP=0 -DWAMR_BUILD_INTERP=0 -DWAMR_BUILD_JIT=1 -DWAMR_BUILD_LAZY_JIT=0"
5656

5757
jobs:
58-
build_llvm_libraries:
58+
build_llvm_libraries_on_intel_macos:
5959
uses: ./.github/workflows/build_llvm_libraries.yml
6060
with:
6161
os: "macos-latest"
6262
arch: "X86"
63+
build_llvm_libraries_on_arm_macos:
64+
uses: ./.github/workflows/build_llvm_libraries.yml
65+
with:
66+
os: "macos-14"
67+
arch: "AArch64 ARM"
6368

6469
build_wamrc:
65-
needs: [build_llvm_libraries]
70+
needs: [build_llvm_libraries_on_intel_macos]
6671
runs-on: ${{ matrix.os }}
6772
strategy:
6873
matrix:
6974
include:
7075
- os: macos-latest
71-
llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
76+
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
7277
steps:
7378
- name: checkout
7479
uses: actions/checkout@v4
@@ -97,7 +102,7 @@ jobs:
97102
working-directory: wamr-compiler
98103

99104
build_iwasm:
100-
needs: [build_llvm_libraries]
105+
needs: [build_llvm_libraries_on_intel_macos]
101106
runs-on: ${{ matrix.os }}
102107
strategy:
103108
matrix:
@@ -171,7 +176,7 @@ jobs:
171176
make_options_feature: "-DWAMR_BUILD_MINI_LOADER=1"
172177
include:
173178
- os: macos-latest
174-
llvm_cache_key: ${{ needs.build_llvm_libraries.outputs.cache_key }}
179+
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
175180
steps:
176181
- name: checkout
177182
uses: actions/checkout@v4
@@ -243,11 +248,11 @@ jobs:
243248
working-directory: samples/wasm-c-api
244249

245250
build_samples_others:
246-
needs: [build_iwasm, build_wamrc]
251+
needs: [build_iwasm, build_wamrc, build_llvm_libraries_on_intel_macos, build_llvm_libraries_on_arm_macos]
247252
runs-on: ${{ matrix.os }}
248253
strategy:
249254
matrix:
250-
os: [macos-latest]
255+
os: [macos-latest, macos-14]
251256
wasi_sdk_release:
252257
[
253258
"https://github.com/WebAssembly/wasi-sdk/releases/download/wasi-sdk-20/wasi-sdk-20.0-macos.tar.gz",
@@ -256,6 +261,11 @@ jobs:
256261
[
257262
"https://github.com/WebAssembly/wabt/releases/download/1.0.31/wabt-1.0.31-macos-12.tar.gz",
258263
]
264+
include:
265+
- os: macos-latest
266+
llvm_cache_key: ${{ needs.build_llvm_libraries_on_intel_macos.outputs.cache_key }}
267+
- os: macos-14
268+
llvm_cache_key: ${{ needs.build_llvm_libraries_on_arm_macos.outputs.cache_key }}
259269
steps:
260270
- name: checkout
261271
uses: actions/checkout@v4
@@ -320,6 +330,25 @@ jobs:
320330
cmake --build . --config Debug --parallel 4
321331
./hello
322332
333+
- name: Get LLVM libraries
334+
id: retrieve_llvm_libs
335+
uses: actions/cache@v4
336+
with:
337+
path: |
338+
./core/deps/llvm/build/bin
339+
./core/deps/llvm/build/include
340+
./core/deps/llvm/build/lib
341+
./core/deps/llvm/build/libexec
342+
./core/deps/llvm/build/share
343+
key: ${{ matrix.llvm_cache_key }}
344+
345+
- name: Build wamrc
346+
run: |
347+
mkdir build && cd build
348+
cmake ..
349+
cmake --build . --config Release --parallel 4
350+
working-directory: wamr-compiler
351+
323352
- name: Build Sample [wasi-threads]
324353
run: |
325354
cd samples/wasi-threads
@@ -328,6 +357,9 @@ jobs:
328357
cmake --build . --config Debug --parallel 4
329358
./iwasm wasm-apps/no_pthread.wasm
330359
360+
../../../wamr-compiler/build/wamrc --size-level=0 --enable-multi-thread -o wasm-apps/no_pthread.aot wasm-apps/no_pthread.wasm
361+
./iwasm wasm-apps/no_pthread.aot
362+
331363
- name: Build Sample [shared-module]
332364
run: |
333365
cd samples/shared-module

build-scripts/config_common.cmake

-6
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,6 @@ if (WAMR_BUILD_SHARED_MEMORY EQUAL 1)
248248
else ()
249249
add_definitions (-DWASM_ENABLE_SHARED_MEMORY=0)
250250
endif ()
251-
if (WAMR_ENABLE_SHARED_MEMORY_MMAP EQUAL 1)
252-
add_definitions (-DWASM_ENABLE_SHARED_MEMORY_MMAP=1)
253-
message (" Shared memory allocated using mmap enabled")
254-
else ()
255-
add_definitions (-DWASM_ENABLE_SHARED_MEMORY_MMAP=0)
256-
endif ()
257251
if (WAMR_BUILD_THREAD_MGR EQUAL 1)
258252
message (" Thread manager enabled")
259253
endif ()

core/config.h

+4-5
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,10 @@
188188
#define WASM_ENABLE_APP_FRAMEWORK 0
189189
#endif
190190

191+
#ifndef WASM_HAVE_MREMAP
192+
#define WASM_HAVE_MREMAP 0
193+
#endif
194+
191195
/* Bulk memory operation */
192196
#ifndef WASM_ENABLE_BULK_MEMORY
193197
#define WASM_ENABLE_BULK_MEMORY 0
@@ -567,11 +571,6 @@
567571
#define WASM_ENABLE_QUICK_AOT_ENTRY 1
568572
#endif
569573

570-
/* Disable mmap based shared memory by default */
571-
#ifndef WASM_ENABLE_SHARED_MEMORY_MMAP
572-
#define WASM_ENABLE_SHARED_MEMORY_MMAP 0
573-
#endif
574-
575574
#ifndef WASM_TABLE_MAX_SIZE
576575
#define WASM_TABLE_MAX_SIZE 1024
577576
#endif

core/iwasm/aot/aot_runtime.c

+11-79
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,6 @@ tables_instantiate(AOTModuleInstance *module_inst, AOTModule *module,
751751
static void
752752
memories_deinstantiate(AOTModuleInstance *module_inst)
753753
{
754-
#ifdef WASM_LINEAR_MEMORY_MMAP
755-
uint64 map_size;
756-
#endif
757754
uint32 i;
758755
AOTMemoryInstance *memory_inst;
759756

@@ -775,23 +772,7 @@ memories_deinstantiate(AOTModuleInstance *module_inst)
775772
}
776773

777774
if (memory_inst->memory_data) {
778-
#ifndef OS_ENABLE_HW_BOUND_CHECK
779-
#ifdef WASM_LINEAR_MEMORY_MMAP
780-
if (shared_memory_is_shared(memory_inst)) {
781-
map_size = (uint64)memory_inst->num_bytes_per_page
782-
* memory_inst->max_page_count;
783-
wasm_munmap_linear_memory(memory_inst->memory_data,
784-
map_size, map_size);
785-
}
786-
else
787-
#endif
788-
wasm_runtime_free(memory_inst->memory_data);
789-
#else
790-
map_size = (uint64)memory_inst->num_bytes_per_page
791-
* memory_inst->cur_page_count;
792-
wasm_munmap_linear_memory(memory_inst->memory_data, map_size,
793-
8 * (uint64)BH_GB);
794-
#endif
775+
wasm_deallocate_linear_memory(memory_inst);
795776
}
796777
}
797778
}
@@ -813,14 +794,10 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
813794
uint32 heap_offset = num_bytes_per_page * init_page_count;
814795
uint64 memory_data_size, max_memory_data_size;
815796
uint8 *p = NULL, *global_addr;
816-
#ifdef WASM_LINEAR_MEMORY_MMAP
817-
uint8 *mapped_mem = NULL;
818-
uint64 map_size;
819-
#endif
820797

798+
bool is_shared_memory = false;
821799
#if WASM_ENABLE_SHARED_MEMORY != 0
822-
bool is_shared_memory = memory->memory_flags & 0x02 ? true : false;
823-
800+
is_shared_memory = memory->memory_flags & 0x02 ? true : false;
824801
/* Shared memory */
825802
if (is_shared_memory && parent != NULL) {
826803
AOTMemoryInstance *shared_memory_instance;
@@ -930,55 +907,18 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
930907
module->aux_stack_size);
931908
LOG_VERBOSE(" heap offset: %u, heap size: %d\n", heap_offset, heap_size);
932909

933-
memory_data_size = (uint64)num_bytes_per_page * init_page_count;
934910
max_memory_data_size = (uint64)num_bytes_per_page * max_page_count;
935-
bh_assert(memory_data_size <= UINT32_MAX);
936911
bh_assert(max_memory_data_size <= 4 * (uint64)BH_GB);
937912
(void)max_memory_data_size;
938913

939-
#ifndef OS_ENABLE_HW_BOUND_CHECK
940-
#if WASM_ENABLE_SHARED_MEMORY != 0
941-
if (is_shared_memory) {
942-
#if WASM_ENABLE_SHARED_MEMORY_MMAP != 0
943-
map_size = max_memory_data_size;
944-
if (max_memory_data_size > 0
945-
&& !(p = mapped_mem =
946-
wasm_mmap_linear_memory(map_size, &max_memory_data_size,
947-
error_buf, error_buf_size))) {
948-
return NULL;
949-
}
950-
#else
951-
/* Allocate maximum memory size when memory is shared */
952-
if (max_memory_data_size > 0
953-
&& !(p = runtime_malloc(max_memory_data_size, error_buf,
954-
error_buf_size))) {
955-
return NULL;
956-
}
957-
#endif
958-
}
959-
else
960-
#endif /* end of WASM_ENABLE_SHARED_MEMORY != 0 */
961-
{
962-
/* Allocate initial memory size when memory is not shared */
963-
if (memory_data_size > 0
964-
&& !(p = runtime_malloc(memory_data_size, error_buf,
965-
error_buf_size))) {
966-
return NULL;
967-
}
968-
}
969-
#else /* else of OS_ENABLE_HW_BOUND_CHECK */
970-
/* Totally 8G is mapped, the opcode load/store address range is 0 to 8G:
971-
* ea = i + memarg.offset
972-
* both i and memarg.offset are u32 in range 0 to 4G
973-
* so the range of ea is 0 to 8G
974-
*/
975-
map_size = 8 * (uint64)BH_GB;
976-
if (!(p = mapped_mem = wasm_mmap_linear_memory(
977-
map_size, &memory_data_size, error_buf, error_buf_size))) {
978-
set_error_buf(error_buf, error_buf_size, "mmap memory failed");
914+
if (wasm_allocate_linear_memory(&p, is_shared_memory, num_bytes_per_page,
915+
init_page_count, max_page_count,
916+
&memory_data_size)
917+
!= BHT_OK) {
918+
set_error_buf(error_buf, error_buf_size,
919+
"allocate linear memory failed");
979920
return NULL;
980921
}
981-
#endif /* end of OS_ENABLE_HW_BOUND_CHECK */
982922

983923
memory_inst->module_type = Wasm_Module_AoT;
984924
memory_inst->num_bytes_per_page = num_bytes_per_page;
@@ -1028,16 +968,8 @@ memory_instantiate(AOTModuleInstance *module_inst, AOTModuleInstance *parent,
1028968
if (heap_size > 0)
1029969
wasm_runtime_free(memory_inst->heap_handle);
1030970
fail1:
1031-
#ifdef WASM_LINEAR_MEMORY_MMAP
1032-
if (mapped_mem)
1033-
wasm_munmap_linear_memory(mapped_mem, memory_data_size, map_size);
1034-
else
1035-
#endif
1036-
{
1037-
if (memory_inst->memory_data)
1038-
wasm_runtime_free(memory_inst->memory_data);
1039-
}
1040-
memory_inst->memory_data = NULL;
971+
wasm_deallocate_linear_memory(memory_inst);
972+
1041973
return NULL;
1042974
}
1043975

0 commit comments

Comments
 (0)