From ee8a068d8ab3fb255538c64802bffc452496adeb Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 10:04:25 +0800 Subject: [PATCH 01/26] Adapt BUILD.gn --- BUILD.gn | 6 ++++++ assembler/BUILD.gn | 1 - disassembler/BUILD.gn | 1 - gn/ark-third-party/securec/BUILD.gn | 2 -- libpandabase/BUILD.gn | 1 - libpandafile/BUILD.gn | 1 - libpandafile/external/BUILD.gn | 2 -- libziparchive/BUILD.gn | 1 - runtime/BUILD.gn | 2 -- 9 files changed, 6 insertions(+), 11 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index f30ca7fdd9..20bd2c161c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -24,6 +24,12 @@ group("ark_packages") { } } +group("ark_packages_for_windows") { + deps = [ + "$ark_root/runtime:libarkruntime(//build/toolchain/mingw:mingw_x86_64)", + ] +} + group("ark_host_linux_tools_packages") { if (host_os != "mac") { deps = [ diff --git a/assembler/BUILD.gn b/assembler/BUILD.gn index ecf04b5de7..b448632568 100644 --- a/assembler/BUILD.gn +++ b/assembler/BUILD.gn @@ -68,7 +68,6 @@ ohos_shared_library("libarkassembler") { if (!is_standard_system) { relative_install_dir = "ark" } - output_extension = "so" subsystem_name = "ark" } diff --git a/disassembler/BUILD.gn b/disassembler/BUILD.gn index fa244bc203..c88e46ba90 100644 --- a/disassembler/BUILD.gn +++ b/disassembler/BUILD.gn @@ -55,7 +55,6 @@ ohos_shared_library("arkdisassembler") { if (!is_standard_system) { relative_install_dir = "ark" } - output_extension = "so" subsystem_name = "ark" } diff --git a/gn/ark-third-party/securec/BUILD.gn b/gn/ark-third-party/securec/BUILD.gn index 8479aad074..60b0f4406d 100644 --- a/gn/ark-third-party/securec/BUILD.gn +++ b/gn/ark-third-party/securec/BUILD.gn @@ -86,6 +86,4 @@ ohos_shared_library("libc_secshared") { "-D_INC_STDLIB_S", "-D_INC_MEMORY_S", ] - - output_extension = "so" } diff --git a/libpandabase/BUILD.gn b/libpandabase/BUILD.gn index d5404d9b59..0a26dd2eb0 100644 --- a/libpandabase/BUILD.gn +++ b/libpandabase/BUILD.gn @@ -129,7 +129,6 @@ ohos_shared_library("libarkbase") { deps = libarkbase_deps - output_extension = "so" if (!is_standard_system) { relative_install_dir = "ark" } diff --git a/libpandafile/BUILD.gn b/libpandafile/BUILD.gn index 6d9b5e656f..fef96edfa9 100644 --- a/libpandafile/BUILD.gn +++ b/libpandafile/BUILD.gn @@ -78,7 +78,6 @@ ohos_shared_library("libarkfile") { if (!is_standard_system) { relative_install_dir = "ark" } - output_extension = "so" subsystem_name = "ark" } diff --git a/libpandafile/external/BUILD.gn b/libpandafile/external/BUILD.gn index 8ef779789d..6a0bfcde0e 100644 --- a/libpandafile/external/BUILD.gn +++ b/libpandafile/external/BUILD.gn @@ -39,7 +39,6 @@ ohos_shared_library("libarkfileExt") { if (!is_standard_system) { relative_install_dir = "ark" } - output_extension = "so" subsystem_name = "ark" } @@ -68,6 +67,5 @@ ohos_shared_library("libarksupport") { if (!is_standard_system) { relative_install_dir = "ark" } - output_extension = "so" subsystem_name = "ark" } diff --git a/libziparchive/BUILD.gn b/libziparchive/BUILD.gn index 7b050e19ef..1bbe377766 100644 --- a/libziparchive/BUILD.gn +++ b/libziparchive/BUILD.gn @@ -52,7 +52,6 @@ ohos_shared_library("libarkziparchive") { if (!is_standard_system) { relative_install_dir = "ark" } - output_extension = "so" subsystem_name = "ark" } diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index eef4721019..d9e0be1a46 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -250,14 +250,12 @@ ohos_static_library("libarkruntime_static") { ldflags = [ "-latomic" ] } - output_extension = "a" subsystem_name = "ark" } ohos_shared_library("libarkruntime") { deps = [ ":libarkruntime_static" ] - output_extension = "so" if (!is_standard_system) { relative_install_dir = "ark" } -- Gitee From 716a3ac975c591c3d830f2b31a7b84c35c72164e Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 10:14:03 +0800 Subject: [PATCH 02/26] Exclude 'dprof' on windows since 'fcntl' not supported in MinGw --- runtime/BUILD.gn | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index d9e0be1a46..ec35a4fba4 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -214,7 +214,6 @@ ohos_static_library("libarkruntime_static") { deps = [ ":arkruntime_header_deps", ":arkruntime_interpreter_impl", - "$ark_root/dprof:libdprof", "$ark_root/libpandabase:libarkbase", "$ark_root/libpandafile:libarkfile", "$ark_root/libpandafile:libarkfile_type_gen_h", @@ -223,6 +222,12 @@ ohos_static_library("libarkruntime_static") { sdk_libc_secshared_dep, ] + if (is_linux) { + deps += [ + "$ark_root/dprof:libdprof", + ] + } + if (is_standard_system) { cflags_cc = [ "-fvisibility=hidden" ] } -- Gitee From d24fab75f493dfe8a8d4b3ab3c46d5acf8b4c422 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 10:18:41 +0800 Subject: [PATCH 03/26] Specify parameter type since 'uint' not available in MinGw --- runtime/mem/mem_stats.h | 2 +- runtime/mem/mem_stats_additional_info.cpp | 2 +- runtime/mem/mem_stats_additional_info.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/runtime/mem/mem_stats.h b/runtime/mem/mem_stats.h index 31b442140c..5c4a8c263d 100644 --- a/runtime/mem/mem_stats.h +++ b/runtime/mem/mem_stats.h @@ -120,7 +120,7 @@ private: duration min_pause_ = duration(0); duration max_pause_ = duration(0); duration sum_pause_ = duration(0); - uint pause_count_ = 0; + uint64_t pause_count_ = 0; // make groups of different parts of the VM (JIT, interpreter, etc) std::atomic_uint64_t objects_allocated_ = 0; diff --git a/runtime/mem/mem_stats_additional_info.cpp b/runtime/mem/mem_stats_additional_info.cpp index e2f299007e..669eb70d0c 100644 --- a/runtime/mem/mem_stats_additional_info.cpp +++ b/runtime/mem/mem_stats_additional_info.cpp @@ -65,7 +65,7 @@ void MemStatsAdditionalInfo::RecordGCPhaseEnd() os::memory::LockHolder lk(phase_lock_); ASSERT(current_phase_ != GCPhase::GC_PHASE_LAST); - uint phase_index = ToIndex(current_phase_); + uint64_t phase_index = ToIndex(current_phase_); duration phase_time = clock::now() - phase_start_time_; if (phase_count_[phase_index] != 0) { min_phase_time_[phase_index] = std::min(min_phase_time_[phase_index], phase_time); diff --git a/runtime/mem/mem_stats_additional_info.h b/runtime/mem/mem_stats_additional_info.h index 6ed7b55554..4f9f767383 100644 --- a/runtime/mem/mem_stats_additional_info.h +++ b/runtime/mem/mem_stats_additional_info.h @@ -57,7 +57,7 @@ private: std::array min_phase_time_ = {}; std::array max_phase_time_ = {}; std::array sum_phase_time_ = {}; - std::array phase_count_ = {}; + std::array phase_count_ = {}; os::memory::Mutex phase_lock_; }; -- Gitee From d43b7e65ed61c1e94a5c9c98bc90802a32c38be9 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 10:30:56 +0800 Subject: [PATCH 04/26] Exclude debugger on windows since 'dlopen' not available in MinGw --- runtime/include/runtime.h | 10 ++++++++++ runtime/runtime.cpp | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index a1c35cf318..c53bb2a727 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -24,7 +24,9 @@ #include "libpandabase/mem/arena_allocator.h" #include "libpandabase/os/mutex.h" +#ifndef PANDA_TARGET_WINDOWS #include "libpandabase/os/library_loader.h" +#endif #include "libpandabase/utils/expected.h" #include "libpandabase/utils/dfx.h" #include "libpandafile/file_items.h" @@ -160,10 +162,12 @@ public: is_debug_mode_ = is_debug_mode; } +#ifndef PANDA_TARGET_WINDOWS void SetDebuggerLibrary(os::library_loader::LibraryHandle debugger_library) { debugger_library_ = std::move(debugger_library); } +#endif bool IsDebuggerConnected() const { @@ -318,7 +322,9 @@ public: static mem::GCType GetGCType(const RuntimeOptions &options); +#ifndef PANDA_TARGET_WINDOWS bool AttachDebugger(); +#endif mem::InternalAllocatorPtr GetInternalAllocator() const { @@ -351,7 +357,9 @@ private: bool LoadBootPandaFiles(panda_file::File::OpenMode open_mode); +#ifndef PANDA_TARGET_WINDOWS bool StartDebugger(const std::string &library_path); +#endif bool IsEnableMemoryHooks() const; @@ -388,7 +396,9 @@ private: bool is_debugger_connected_ {false}; tooling::PtLangExt *pt_lang_ext_ {nullptr}; tooling::DebugInterface *debugger_ {nullptr}; +#ifndef PANDA_TARGET_WINDOWS os::library_loader::LibraryHandle debugger_library_; +#endif // Additional VMInfo std::string process_package_name_; diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp index 95385690d5..3f1d97c731 100644 --- a/runtime/runtime.cpp +++ b/runtime/runtime.cpp @@ -26,7 +26,9 @@ #include "libpandabase/events/events.h" #include "libpandabase/mem/mem_config.h" #include "libpandabase/mem/pool_manager.h" +#ifndef PANDA_TARGET_WINDOWS #include "libpandabase/os/library_loader.h" +#endif #include "libpandabase/os/native_stack.h" #include "libpandabase/os/thread.h" #include "libpandabase/utils/arena_containers.h" @@ -381,7 +383,9 @@ Runtime::Runtime(const RuntimeOptions &options, mem::InternalAllocatorPtr intern // CODECHECK-NOLINTNEXTLINE(CPP_RULE_ID_SMARTPOINTER_INSTEADOF_ORIGINPOINTER) notification_manager_(new RuntimeNotificationManager(internal_allocator_)), // CODECHECK-NOLINTNEXTLINE(CPP_RULE_ID_SMARTPOINTER_INSTEADOF_ORIGINPOINTER) +#ifndef PANDA_TARGET_WINDOWS debugger_library_(nullptr), +#endif zygote_no_threads_(false) { Runtime::options_ = options; @@ -577,6 +581,7 @@ bool Runtime::InitializePandaVM() return false; } +#ifndef PANDA_TARTET_WINDOWS std::string debug_library_path = options_.GetDebuggerLibraryPath(); if (!debug_library_path.empty()) { if (!StartDebugger(debug_library_path)) { @@ -584,6 +589,7 @@ bool Runtime::InitializePandaVM() return false; } } +#endif if (!panda_vm_->Initialize()) { LOG(ERROR, RUNTIME) << "Failed to initialize panda vm"; @@ -899,6 +905,7 @@ int Runtime::StartDProfiler(std::string_view app_name) return 0; } +#ifndef PANDA_TARGET_WINDOWS bool Runtime::StartDebugger(const std::string &library_path) { auto handle = os::library_loader::Load(library_path); @@ -975,6 +982,15 @@ bool Runtime::Shutdown() return ManagedThread::Shutdown(); } +#else + +bool Runtime::Shutdown() +{ + return ManagedThread::Shutdown(); +} + +#endif // PANDA_TARGET_WINDOWS + coretypes::String *Runtime::ResolveString(PandaVM *vm, const Method &caller, panda_file::File::EntityId id) { auto *pf = caller.GetPandaFile(); -- Gitee From ebfc2da789f4bf22cbc0a6eafd17923e42cec0be Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 10:55:57 +0800 Subject: [PATCH 05/26] Exclude signal manager on windows since 'siginfo_t' not available in MinGw --- runtime/include/runtime.h | 6 ++++++ runtime/runtime.cpp | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index c53bb2a727..31579bfb95 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -36,7 +36,9 @@ #include "runtime/include/runtime_options.h" #include "runtime/include/gc_task.h" #include "runtime/include/tooling/debug_interface.h" +#ifdef PANDA_TARGET_UNIX #include "runtime/signal_handler.h" +#endif #include "runtime/mem/allocator_adapter.h" #include "runtime/mem/gc/gc.h" #include "runtime/mem/gc/gc_trigger.h" @@ -311,10 +313,12 @@ public: return is_stacktrace_; } +#ifdef PANDA_TARGET_UNIX SignalManager *GetSignalManager() { return signal_manager_; } +#endif Trace *CreateTrace(LanguageContext ctx, PandaUniquePtr trace_file, size_t buffer_size); @@ -385,7 +389,9 @@ private: PandaVM *panda_vm_ = nullptr; +#ifdef PANDA_TARGET_UNIX SignalManager *signal_manager_ {nullptr}; +#endif // Language context static constexpr size_t LANG_EXTENSIONS_COUNT = static_cast(panda_file::SourceLang::LAST) + 1; diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp index 3f1d97c731..c124a308ae 100644 --- a/runtime/runtime.cpp +++ b/runtime/runtime.cpp @@ -414,7 +414,9 @@ Runtime::Runtime(const RuntimeOptions &options, mem::InternalAllocatorPtr intern // CODECHECK-NOLINTNEXTLINE(CPP_RULE_ID_SMARTPOINTER_INSTEADOF_ORIGINPOINTER) class_linker_ = new ClassLinker(internal_allocator_, std::move(extensions)); // CODECHECK-NOLINTNEXTLINE(CPP_RULE_ID_SMARTPOINTER_INSTEADOF_ORIGINPOINTER) +#ifdef PANDA_TARGET_UNIX signal_manager_ = new SignalManager(internal_allocator_); +#endif if (IsEnableMemoryHooks()) { // libbfd (which is used to get debug info from elf files) does a lot of allocations. @@ -442,8 +444,10 @@ Runtime::~Runtime() } trace::ScopedTrace scoped_trace("Delete state"); +#ifdef PANDA_TARGET_UNIX signal_manager_->DeleteHandlersArray(); delete signal_manager_; +#endif delete class_linker_; if (dprofiler_ != nullptr) { internal_allocator_->Delete(dprofiler_); -- Gitee From ab8ced8ecf9f94879c916e490d47fb87a0187e43 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 11:03:03 +0800 Subject: [PATCH 06/26] Remove CreateTrace on windows since it depends on unix file --- runtime/include/runtime.h | 2 +- runtime/runtime.cpp | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 31579bfb95..7ece091974 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -318,9 +318,9 @@ public: { return signal_manager_; } -#endif Trace *CreateTrace(LanguageContext ctx, PandaUniquePtr trace_file, size_t buffer_size); +#endif // PANDA_TARGET_UNIX void SetPtLangExt(tooling::PtLangExt *pt_lang_ext); diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp index c124a308ae..26351a0f2b 100644 --- a/runtime/runtime.cpp +++ b/runtime/runtime.cpp @@ -1199,6 +1199,7 @@ bool Runtime::SaveProfileInfo() const return save_profiling_info_; } +#ifdef PANDA_TARGET_UNIX Trace *Runtime::CreateTrace([[maybe_unused]] LanguageContext ctx, [[maybe_unused]] PandaUniquePtr trace_file, [[maybe_unused]] size_t buffer_size) @@ -1206,4 +1207,6 @@ Trace *Runtime::CreateTrace([[maybe_unused]] LanguageContext ctx, LOG(FATAL, RUNTIME) << "Method tracing isn't supported at the moment!"; return nullptr; } +#endif + } // namespace panda -- Gitee From e379d5fde1ff1c988e069c4eeba47a79c41340fe Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 11:09:07 +0800 Subject: [PATCH 07/26] Only define PandaThreadSigmask on unix platform --- libpandabase/os/native_stack.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libpandabase/os/native_stack.h b/libpandabase/os/native_stack.h index 536b252e60..bf0ef02826 100644 --- a/libpandabase/os/native_stack.h +++ b/libpandabase/os/native_stack.h @@ -25,8 +25,8 @@ namespace panda::os::native_stack { -const auto g_PandaThreadSigmask = pthread_sigmask; // NOLINT(readability-identifier-naming) #if defined(PANDA_TARGET_UNIX) +const auto g_PandaThreadSigmask = pthread_sigmask; // NOLINT(readability-identifier-naming) using DumpUnattachedThread = panda::os::unix::native_stack::DumpUnattachedThread; const auto DumpKernelStack = panda::os::unix::native_stack::DumpKernelStack; // NOLINT(readability-identifier-naming) const auto GetNativeThreadNameForFile = // NOLINT(readability-identifier-naming) -- Gitee From 0fd73e27e1db64c53f4f0a91fb4c34a365b2aa3b Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 11:14:15 +0800 Subject: [PATCH 08/26] Avoid duplicated macro definition since MinGw defined one --- runtime/class_linker.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/runtime/class_linker.cpp b/runtime/class_linker.cpp index df73d2b1b8..f5c7e48f8e 100644 --- a/runtime/class_linker.cpp +++ b/runtime/class_linker.cpp @@ -944,10 +944,13 @@ Class *ClassLinker::LoadArrayClass(const uint8_t *descriptor, bool need_copy_des return nullptr; } +#if defined(PANDA_TARGET_WINDOWS) && defined(VOID) +#undef VOID if (UNLIKELY(component_class->GetType().GetId() == panda_file::Type::TypeId::VOID)) { OnError(error_handler, Error::NO_CLASS_DEF, "Try to create array with void component type"); return nullptr; } +#endif auto *ext = GetExtension(component_class->GetSourceLang()); ASSERT(ext != nullptr); -- Gitee From b3ee3e7aba71180da0a675a5ad05c7a6e76f4318 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 12:04:41 +0800 Subject: [PATCH 09/26] Include securec file --- runtime/mem/gc/crossing_map.cpp | 1 + runtime/mem/region_space.cpp | 1 + runtime/mem/runslots.cpp | 1 + 3 files changed, 3 insertions(+) diff --git a/runtime/mem/gc/crossing_map.cpp b/runtime/mem/gc/crossing_map.cpp index 46562e8e38..790579d4c1 100644 --- a/runtime/mem/gc/crossing_map.cpp +++ b/runtime/mem/gc/crossing_map.cpp @@ -14,6 +14,7 @@ */ #include "runtime/mem/gc/crossing_map.h" +#include "securec.h" #include diff --git a/runtime/mem/region_space.cpp b/runtime/mem/region_space.cpp index b80b7233ef..1989373786 100644 --- a/runtime/mem/region_space.cpp +++ b/runtime/mem/region_space.cpp @@ -14,6 +14,7 @@ */ #include "runtime/mem/region_space-inl.h" #include "runtime/mem/rem_set-inl.h" +#include "securec.h" namespace panda::mem { diff --git a/runtime/mem/runslots.cpp b/runtime/mem/runslots.cpp index 9a3398ae57..65274f1b20 100644 --- a/runtime/mem/runslots.cpp +++ b/runtime/mem/runslots.cpp @@ -18,6 +18,7 @@ #include #include "runtime/include/object_header.h" +#include "securec.h" namespace panda::mem { -- Gitee From 433595ec5265b959e7c934d0a17705e2bc809ca4 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 12:10:11 +0800 Subject: [PATCH 10/26] Exclude mem hooks on windows since it is not available in MinGw --- runtime/mem/mem_hooks.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/runtime/mem/mem_hooks.cpp b/runtime/mem/mem_hooks.cpp index 0a0700045a..b78cf92fe7 100644 --- a/runtime/mem/mem_hooks.cpp +++ b/runtime/mem/mem_hooks.cpp @@ -22,17 +22,21 @@ namespace panda::mem { size_t PandaHooks::alloc_via_standard = 0; +#ifndef PANDA_TARGET_WINDOWS void *(*volatile PandaHooks::old_malloc_hook)(size_t, const void *) = nullptr; void *(*volatile PandaHooks::old_memalign_hook)(size_t, size_t, const void *) = nullptr; void (*volatile PandaHooks::old_free_hook)(void *, const void *) = nullptr; +#endif // PANDA_TARGET_WINDOWS /* static */ void PandaHooks::SaveMemHooks() { #ifndef __MUSL__ +#ifndef PANDA_TARGET_WINDOWS old_malloc_hook = __malloc_hook; old_memalign_hook = __memalign_hook; old_free_hook = __free_hook; +#endif // PANDA_TARGET_WINDOWS #endif // __MUSL__ } @@ -40,9 +44,11 @@ void PandaHooks::SaveMemHooks() void PandaHooks::SetMemHooks() { #ifndef __MUSL__ +#ifndef PANDA_TARGET_WINDOWS __malloc_hook = MallocHook; __memalign_hook = MemalignHook; __free_hook = FreeHook; +#endif // PANDA_TARGET_WINDOWS #endif // __MUSL__ } @@ -67,6 +73,7 @@ void *PandaHooks::MallocHook(size_t size, [[maybe_unused]] const void *caller) return result; } +#ifndef PANDA_TARGET_WINDOWS /* static */ void *PandaHooks::MemalignHook(size_t alignment, size_t size, [[maybe_unused]] const void *caller) { @@ -87,6 +94,7 @@ void *PandaHooks::MemalignHook(size_t alignment, size_t size, [[maybe_unused]] c SetMemHooks(); return result; } +#endif // PANDA_TARGET_WINDOWS /* static */ void PandaHooks::FreeHook(void *ptr, [[maybe_unused]] const void *caller) @@ -108,9 +116,11 @@ void PandaHooks::Enable() void PandaHooks::Disable() { #ifndef __MUSL__ +#ifndef PANDA_TARGET_WINDOWS __malloc_hook = old_malloc_hook; __memalign_hook = old_memalign_hook; __free_hook = old_free_hook; +#endif // PANDA_TARGET_WINDOWS #endif // __MUSL__ } -- Gitee From 594e870f104518cc232bfa6ebc6b39dcf6b8914c Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 12:10:49 +0800 Subject: [PATCH 11/26] Use '_aligned_malloc' instead of 'aligned_alloc' on windows --- runtime/mem/malloc-proxy-allocator-inl.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/runtime/mem/malloc-proxy-allocator-inl.h b/runtime/mem/malloc-proxy-allocator-inl.h index 57eb1df1b2..f5c8ae40a8 100644 --- a/runtime/mem/malloc-proxy-allocator-inl.h +++ b/runtime/mem/malloc-proxy-allocator-inl.h @@ -48,7 +48,11 @@ void *MallocProxyAllocator::Alloc(size_t size, Alignment align) } size_t alignment_in_bytes = GetAlignmentInBytes(align); size_t aligned_size = (size + alignment_in_bytes - 1) & ~(alignment_in_bytes - 1); +#ifndef PANDA_TARGET_WINDOWS void *ret = aligned_alloc(alignment_in_bytes, aligned_size); +#else + void *ret = _aligned_malloc(aligned_size, alignment_in_bytes); +#endif // NOLINTNEXTLINE(readability-braces-around-statements, bugprone-suspicious-semicolon) if constexpr (!DUMMY_ALLOC_CONFIG) { ASSERT(allocated_memory_.find(ret) == allocated_memory_.end()); -- Gitee From 308a461ef35972ae02faf94a60da36b81f62c17f Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 14:32:32 +0800 Subject: [PATCH 12/26] Use macro to isolate some UNIX DfxOptionHandler on windows --- runtime/mem/refstorage/global_object_storage.h | 8 ++++++-- runtime/mem/refstorage/reference_storage.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/runtime/mem/refstorage/global_object_storage.h b/runtime/mem/refstorage/global_object_storage.h index 0162242cc8..22badc6de6 100644 --- a/runtime/mem/refstorage/global_object_storage.h +++ b/runtime/mem/refstorage/global_object_storage.h @@ -335,8 +335,12 @@ private: void Dump() REQUIRES_SHARED(mutex_) { - if (DfxController::IsInitialized() && - DfxController::GetOptionValue(DfxOptionHandler::REFERENCE_DUMP) != 1) { + if (DfxController::IsInitialized()) { +#ifdef PANDA_TARGET_UNIX + if (DfxController::GetOptionValue(DfxOptionHandler::REFERENCE_DUMP) != 1) { + return; + } +#endif return; } static constexpr size_t DUMP_NUMS = 20; diff --git a/runtime/mem/refstorage/reference_storage.cpp b/runtime/mem/refstorage/reference_storage.cpp index 4e960817d4..282c570df2 100644 --- a/runtime/mem/refstorage/reference_storage.cpp +++ b/runtime/mem/refstorage/reference_storage.cpp @@ -372,7 +372,12 @@ void ReferenceStorage::DumpLocalRefClasses() void ReferenceStorage::DumpLocalRef() { - if (DfxController::IsInitialized() && DfxController::GetOptionValue(DfxOptionHandler::REFERENCE_DUMP) != 1) { + if (DfxController::IsInitialized()) { +#ifdef PANDA_TARGET_UNIX + if (DfxController::GetOptionValue(DfxOptionHandler::REFERENCE_DUMP) != 1) { + return; + } +#endif return; } LOG(ERROR, RUNTIME) << "--- local reference storage dump ---"; -- Gitee From 5b9ec2b8c7abd8c4a8aa5cfae3334e447f625bdf Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 14:49:44 +0800 Subject: [PATCH 13/26] Ignore '.type' debug info in '.S' for windows since it is not supported --- runtime/arch/amd64/interpreter_support.S | 2 ++ .../arch/amd64/compiled_code_to_interpreter_bridge_amd64.S | 2 ++ .../amd64/compiled_code_to_interpreter_bridge_dyn_amd64.S | 2 ++ .../bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S | 2 ++ .../arch/amd64/interpreter_to_compiled_code_bridge_amd64.S | 4 ++++ .../amd64/interpreter_to_compiled_code_bridge_dyn_amd64.S | 4 ++++ 6 files changed, 16 insertions(+) diff --git a/runtime/arch/amd64/interpreter_support.S b/runtime/arch/amd64/interpreter_support.S index bae94a8fc5..85ebb21f48 100644 --- a/runtime/arch/amd64/interpreter_support.S +++ b/runtime/arch/amd64/interpreter_support.S @@ -13,7 +13,9 @@ * limitations under the License. */ +#ifndef PANDA_TARGET_WINDOWS .type ExecuteImplStub, @function +#endif .global ExecuteImplStub .balign 16 ExecuteImplStub: diff --git a/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_amd64.S b/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_amd64.S index 21d5a3186c..cb3bbea8f1 100644 --- a/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_amd64.S +++ b/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_amd64.S @@ -30,7 +30,9 @@ .extern IncrementHotnessCounter .global CompiledCodeToInterpreterBridge +#ifndef PANDA_TARGET_WINDOWS .type CompiledCodeToInterpreterBridge, %function +#endif CompiledCodeToInterpreterBridge: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) diff --git a/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_dyn_amd64.S b/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_dyn_amd64.S index f006991da0..1151797d9a 100644 --- a/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_dyn_amd64.S +++ b/runtime/bridge/arch/amd64/compiled_code_to_interpreter_bridge_dyn_amd64.S @@ -29,7 +29,9 @@ // CompiledCodeToInterpreterBridgeDyn(Method* method, uint32_t num_args, int64_t func_obj, int64_t func_tag, int64_t arg_i, int64_t tag_i, ...) .global CompiledCodeToInterpreterBridgeDyn +#ifndef PANDA_TARGET_WINDOWS .type CompiledCodeToInterpreterBridgeDyn, %function +#endif CompiledCodeToInterpreterBridgeDyn: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) diff --git a/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S b/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S index 273d7e8d2d..e67c02a80e 100644 --- a/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S +++ b/runtime/bridge/arch/amd64/compiled_code_to_runtime_bridge_amd64.S @@ -17,7 +17,9 @@ .macro ENTRYPOINT name, entry, paramsnum .global \name +#ifndef PANDA_TARGET_WINDOWS .type \name, %function +#endif \name: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) diff --git a/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_amd64.S b/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_amd64.S index 0090d82e86..d1106b8647 100644 --- a/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_amd64.S +++ b/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_amd64.S @@ -261,7 +261,9 @@ // void InterpreterToCompiledCodeBridge(const BytecodeInstruction* insn, const Frame *iframe, const Method *method, ManagedThread* thread) .global InterpreterToCompiledCodeBridge +#ifndef PANDA_TARGET_WINDOWS .type InterpreterToCompiledCodeBridge, %function +#endif InterpreterToCompiledCodeBridge: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) @@ -450,7 +452,9 @@ InterpreterToCompiledCodeBridge: // DecodedTaggedValue InvokeCompiledCodeWithArguments(const int64_t* args, const Frame *iframe, const Method *method, ManagedThread* thread) .global InvokeCompiledCodeWithArgArray +#ifndef PANDA_TARGET_WINDOWS .type InvokeCompiledCodeWithArgArray, %function +#endif InvokeCompiledCodeWithArgArray: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) diff --git a/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_dyn_amd64.S b/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_dyn_amd64.S index 6183b71cdb..d71c334848 100644 --- a/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_dyn_amd64.S +++ b/runtime/bridge/arch/amd64/interpreter_to_compiled_code_bridge_dyn_amd64.S @@ -21,7 +21,9 @@ // const Method*, %rdx // ManagedThread* thread) %rcx .global InterpreterToCompiledCodeBridgeDyn +#ifndef PANDA_TARGET_WINDOWS .type InterpreterToCompiledCodeBridgeDyn, %function +#endif InterpreterToCompiledCodeBridgeDyn: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) @@ -125,7 +127,9 @@ InterpreterToCompiledCodeBridgeDyn: // const Method*, %rcx // ManagedThread* thread) %r8 .global InvokeCompiledCodeWithArgArrayDyn +#ifndef PANDA_TARGET_WINDOWS .type InvokeCompiledCodeWithArgArrayDyn, %function +#endif InvokeCompiledCodeWithArgArrayDyn: CFI_STARTPROC CFI_DEF_CFA(rsp, 8) -- Gitee From bde46e28e50ecd7f13a722291cfb9c4d71a93c63 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 15:08:31 +0800 Subject: [PATCH 14/26] Include securec file --- verification/debug/config_load.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/verification/debug/config_load.cpp b/verification/debug/config_load.cpp index 2871db0dd3..4ce3dc91d7 100644 --- a/verification/debug/config_load.cpp +++ b/verification/debug/config_load.cpp @@ -25,9 +25,7 @@ #include "verification/debug/breakpoint/breakpoint_private.h" #include "verification/debug/allowlist/allowlist_private.h" -#if !PANDA_TARGET_WINDOWS #include "securec.h" -#endif #include "utils/logger.h" #include "libpandabase/os/file.h" -- Gitee From 2f0a9d4cd1e751eef63234bdaf68f69bb8db251d Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 15:32:57 +0800 Subject: [PATCH 15/26] Exclude debugger on windows since 'dlopen' not available in MinGw --- runtime/include/runtime.h | 4 ---- runtime/runtime.cpp | 19 ++++++------------- 2 files changed, 6 insertions(+), 17 deletions(-) diff --git a/runtime/include/runtime.h b/runtime/include/runtime.h index 7ece091974..a697ce26d8 100644 --- a/runtime/include/runtime.h +++ b/runtime/include/runtime.h @@ -326,9 +326,7 @@ public: static mem::GCType GetGCType(const RuntimeOptions &options); -#ifndef PANDA_TARGET_WINDOWS bool AttachDebugger(); -#endif mem::InternalAllocatorPtr GetInternalAllocator() const { @@ -361,9 +359,7 @@ private: bool LoadBootPandaFiles(panda_file::File::OpenMode open_mode); -#ifndef PANDA_TARGET_WINDOWS bool StartDebugger(const std::string &library_path); -#endif bool IsEnableMemoryHooks() const; diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp index 26351a0f2b..dc8a315510 100644 --- a/runtime/runtime.cpp +++ b/runtime/runtime.cpp @@ -585,7 +585,6 @@ bool Runtime::InitializePandaVM() return false; } -#ifndef PANDA_TARTET_WINDOWS std::string debug_library_path = options_.GetDebuggerLibraryPath(); if (!debug_library_path.empty()) { if (!StartDebugger(debug_library_path)) { @@ -593,7 +592,6 @@ bool Runtime::InitializePandaVM() return false; } } -#endif if (!panda_vm_->Initialize()) { LOG(ERROR, RUNTIME) << "Failed to initialize panda vm"; @@ -909,9 +907,9 @@ int Runtime::StartDProfiler(std::string_view app_name) return 0; } -#ifndef PANDA_TARGET_WINDOWS bool Runtime::StartDebugger(const std::string &library_path) { +#ifndef PANDA_TARGET_WINDOWS auto handle = os::library_loader::Load(library_path); if (!handle) { return true; @@ -944,6 +942,9 @@ bool Runtime::StartDebugger(const std::string &library_path) // Turn off stdout buffering in debug mode setvbuf(stdout, nullptr, _IONBF, 0); return true; +#else + return false; +#endif } bool Runtime::AttachDebugger() @@ -962,6 +963,7 @@ bool Runtime::AttachDebugger() bool Runtime::Shutdown() { +#ifndef PANDA_TARGET_WINDOWS if (IsDebugMode() && debugger_library_.IsValid()) { using StopDebugger = int (*)(); @@ -982,19 +984,10 @@ bool Runtime::Shutdown() if (debugger_ != nullptr) { internal_allocator_->Delete(debugger_); } - - return ManagedThread::Shutdown(); -} - -#else - -bool Runtime::Shutdown() -{ +#endif // PANDA_TARGET_WINDOWS return ManagedThread::Shutdown(); } -#endif // PANDA_TARGET_WINDOWS - coretypes::String *Runtime::ResolveString(PandaVM *vm, const Method &caller, panda_file::File::EntityId id) { auto *pf = caller.GetPandaFile(); -- Gitee From 82322533f677dce1ed50f2da1001a10242f87428 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 15:41:13 +0800 Subject: [PATCH 16/26] Adapt to pthread_create function for windows --- libpandabase/os/thread.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libpandabase/os/thread.h b/libpandabase/os/thread.h index 05cb783073..b1ad91ce9a 100644 --- a/libpandabase/os/thread.h +++ b/libpandabase/os/thread.h @@ -22,6 +22,7 @@ #include #include #include +#include namespace panda::os::thread { @@ -108,7 +109,11 @@ static void *ProxyFunc(void *args) template native_handle_type ThreadStart(Func *func, Args... args) { +#ifndef PANDA_TARGET_WINDOWS native_handle_type tid; +#else + pthread_t tid; +#endif auto args_tuple = std::make_tuple(func, std::move(args)...); internal::SharedPtrStruct *ptr = nullptr; { @@ -124,7 +129,11 @@ native_handle_type ThreadStart(Func *func, Args... args) pthread_create(&tid, nullptr, &internal::ProxyFunc::value>, static_cast(ptr)); +#ifndef PANDA_TARGET_WINDOWS return tid; +#else + return reinterpret_cast(tid); +#endif } } // namespace panda::os::thread -- Gitee From 4570c3024d28b6e6441e06ddd5e74da6a46fb289 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 15:48:51 +0800 Subject: [PATCH 17/26] Avoid duplicated macro definition since KERNEL32.dll defined one --- runtime/arch/asm_support.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/arch/asm_support.cpp b/runtime/arch/asm_support.cpp index 9e28ab670e..8668843be3 100644 --- a/runtime/arch/asm_support.cpp +++ b/runtime/arch/asm_support.cpp @@ -38,10 +38,12 @@ static_assert(FRAME_SLOT_OFFSET == 80U); static_assert(FRAME_TAG_OFFSET == 88U); #endif +#ifndef PANDA_TARGET_WINDOWS extern "C" ManagedThread *GetCurrentThread() { return ManagedThread::GetCurrent(); } +#endif extern "C" void AsmUnreachable() { -- Gitee From ef3b40ae78b68a150810507c405bb227b8b19239 Mon Sep 17 00:00:00 2001 From: huangyu Date: Tue, 1 Mar 2022 21:15:43 +0800 Subject: [PATCH 18/26] Use common os file --- runtime/profilesaver/profile_dump_info.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/runtime/profilesaver/profile_dump_info.cpp b/runtime/profilesaver/profile_dump_info.cpp index 9b70c7a644..167d6fe296 100644 --- a/runtime/profilesaver/profile_dump_info.cpp +++ b/runtime/profilesaver/profile_dump_info.cpp @@ -17,7 +17,9 @@ #include #include +#ifndef PANDA_TARGET_WINDOWS #include +#endif #include #include @@ -517,7 +519,7 @@ bool ProfileDumpInfo::ProcessLine(SerializerBuffer &line_buffer, uint32_t method bool ProfileDumpInfo::MergeAndSave(const PandaString &filename, uint64_t *bytes_written, bool force) { // NB! we using READWRITE mode to leave the creation job to framework layer. - panda::os::unix::file::File myfile = panda::os::file::Open(filename, panda::os::file::Mode::READWRITE); + panda::os::file::File myfile = panda::os::file::Open(filename, panda::os::file::Mode::READWRITE); if (!myfile.IsValid()) { LOG(ERROR, RUNTIME) << "Cannot open the profile file" << filename; return false; -- Gitee From def6861abed1ed839d78ca543e34f9d41538bfb7 Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 15:22:27 +0800 Subject: [PATCH 19/26] Support 'time' function on windows platform --- libpandabase/BUILD.gn | 2 ++ libpandabase/os/windows/time.cpp | 54 ++++++++++++++++++++++++++++++++ libpandabase/os/windows/time.h | 40 +++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 libpandabase/os/windows/time.cpp create mode 100644 libpandabase/os/windows/time.h diff --git a/libpandabase/BUILD.gn b/libpandabase/BUILD.gn index 0a26dd2eb0..838e61ed03 100644 --- a/libpandabase/BUILD.gn +++ b/libpandabase/BUILD.gn @@ -51,11 +51,13 @@ if (is_mingw) { "$ark_root/libpandabase/os/windows/file.cpp", "$ark_root/libpandabase/os/windows/mem.cpp", "$ark_root/libpandabase/os/windows/thread.cpp", + "$ark_root/libpandabase/os/windows/time.cpp", "$ark_root/libpandabase/trace/windows/trace.cpp", "$ark_root/libpandabase/utils/dfx.cpp", "$ark_root/libpandabase/utils/json_parser.cpp", "$ark_root/libpandabase/utils/logger.cpp", "$ark_root/libpandabase/utils/utf.cpp", + "$ark_root/libpandabase/utils/time.cpp", ] } else { libarkbase_sources = [ diff --git a/libpandabase/os/windows/time.cpp b/libpandabase/os/windows/time.cpp new file mode 100644 index 0000000000..f85451943f --- /dev/null +++ b/libpandabase/os/windows/time.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "os/time.h" +#include + +namespace panda::os::time { +template +static uint64_t GetClockTime(clockid_t clock) +{ + struct timespec time = {0, 0}; + if (clock_gettime(clock, &time) != -1) { + auto duration = std::chrono::seconds {time.tv_sec} + std::chrono::nanoseconds {time.tv_nsec}; + return std::chrono::duration_cast(duration).count(); + } + return 0; +} + +/** + * Return current time in nanoseconds + */ +uint64_t GetClockTimeInMicro() +{ + return GetClockTime(CLOCK_MONOTONIC); +} + +/** + * Return current time in milliseconds + */ +uint64_t GetClockTimeInMilli() +{ + return GetClockTime(CLOCK_MONOTONIC); +} + +/** + * Return thread CPU time in nanoseconds + */ +uint64_t GetClockTimeInThreadCpuTime() +{ + return GetClockTime(CLOCK_THREAD_CPUTIME_ID); +} +} // namespace panda::os::time diff --git a/libpandabase/os/windows/time.h b/libpandabase/os/windows/time.h new file mode 100644 index 0000000000..5cde7da2ae --- /dev/null +++ b/libpandabase/os/windows/time.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef PANDA_LIBPANDABASE_OS_WINDOWS_TIME_H_ +#define PANDA_LIBPANDABASE_OS_WINDOWS_TIME_H_ + +#include + +namespace panda::os::windows::time { + +/** + * Return current time in nanoseconds + */ +uint64_t GetClockTimeInMicro(); + +/** + * Return current time in milliseconds + */ +uint64_t GetClockTimeInMilli(); + +/** + * Thread Cpu Time in nanoseconds + */ +uint64_t GetClockTimeInThreadCpuTime(); + +} // namespace panda::os::unix::time + +#endif // PANDA_LIBPANDABASE_OS_WINDOWS_TIME_H_ -- Gitee From 4925e8032237a486dfa11eb044f47b81d469c1f2 Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 15:23:48 +0800 Subject: [PATCH 20/26] Support 'thread' function on windows platform --- libpandabase/os/thread.h | 9 +++++++- libpandabase/os/windows/thread.cpp | 32 ++++++++++++++++++++++++++++ runtime/mem/gc/gc.cpp | 4 ++++ runtime/thread.cpp | 12 +++++++++++ runtime/thread_pool.h | 4 ++++ verification/job_queue/job_queue.cpp | 5 +++++ 6 files changed, 65 insertions(+), 1 deletion(-) diff --git a/libpandabase/os/thread.h b/libpandabase/os/thread.h index b1ad91ce9a..f4e4ca1a9b 100644 --- a/libpandabase/os/thread.h +++ b/libpandabase/os/thread.h @@ -30,15 +30,22 @@ using ThreadId = uint32_t; using native_handle_type = std::thread::native_handle_type; ThreadId GetCurrentThreadId(); +#ifdef PANDA_TARGET_UNIX int SetPriority(int thread_id, int prio); int GetPriority(int thread_id); int SetThreadName(native_handle_type pthread_id, const char *name); +void ThreadJoin(native_handle_type pthread_id, void **retval); +#else +int SetPriority(void *hthread, int prio); +int GetPriority(void *hthread); +int SetThreadName(std::thread::id pthread_id, const char *name); +void ThreadJoin(pthread_t pthread_id, void **retval); +#endif native_handle_type GetNativeHandle(); void Yield(); void NativeSleep(unsigned int ms); void ThreadDetach(native_handle_type pthread_id); void ThreadExit(void *retval); -void ThreadJoin(native_handle_type pthread_id, void **retval); // Templated functions need to be defined here to be accessible everywhere diff --git a/libpandabase/os/windows/thread.cpp b/libpandabase/os/windows/thread.cpp index 76292e80d7..77b7c13383 100644 --- a/libpandabase/os/windows/thread.cpp +++ b/libpandabase/os/windows/thread.cpp @@ -16,6 +16,7 @@ #include "os/thread.h" #include +#include namespace panda::os::thread { @@ -24,4 +25,35 @@ ThreadId GetCurrentThreadId() return static_cast(std::hash()(std::this_thread::get_id())); } +int SetPriority(void *hthread, int prio) +{ + return SetThreadPriority(hthread, prio); +} + +int GetPriority(void *hthread) +{ + return GetThreadPriority(hthread); +} + +int SetThreadName(std::thread::id pthread_id, const char *name) +{ + ASSERT(pthread_id != 0); + return pthread_setname_np(static_cast(std::hash{}(pthread_id)), name); +} + +void Yield() +{ + std::this_thread::yield(); +} + +void NativeSleep(unsigned int ms) +{ + std::this_thread::sleep_for(std::chrono::milliseconds(ms)); +} + +void ThreadJoin(pthread_t pthread_id, void **retval) +{ + pthread_join(pthread_id, retval); +} + } // namespace panda::os::thread diff --git a/runtime/mem/gc/gc.cpp b/runtime/mem/gc/gc.cpp index c1920af15c..0aa8af5153 100644 --- a/runtime/mem/gc/gc.cpp +++ b/runtime/mem/gc/gc.cpp @@ -398,7 +398,11 @@ void GC::CreateWorker() if (worker_ == nullptr) { LOG(FATAL, RUNTIME) << "Cannot create a GC thread"; } +#ifdef PANDA_TARGET_UNIX int res = os::thread::SetThreadName(worker_->native_handle(), "GCThread"); +#else + int res = os::thread::SetThreadName(worker_->get_id(), "GCThread"); +#endif if (res != 0) { LOG(ERROR, RUNTIME) << "Failed to set a name for the gc thread"; } diff --git a/runtime/thread.cpp b/runtime/thread.cpp index 689bb11be1..5cfba062c7 100644 --- a/runtime/thread.cpp +++ b/runtime/thread.cpp @@ -30,6 +30,8 @@ #include "runtime/include/panda_vm.h" #include "runtime/mem/runslots_allocator-inl.h" +#include + namespace panda { using TaggedValue = coretypes::TaggedValue; using TaggedType = coretypes::TaggedType; @@ -453,7 +455,12 @@ bool MTManagedThread::Sleep(uint64_t ms) void ManagedThread::SetThreadPriority(int32_t prio) { ThreadId tid = GetId(); +#ifdef PANDA_TARGET_UNIX int res = os::thread::SetPriority(tid, prio); +#else + auto hthread = GetCurrentThread(); + int res = os::thread::SetPriority(hthread, prio); +#endif if (res == 0) { LOG(DEBUG, RUNTIME) << "Successfully changed priority for thread " << tid << " to " << prio; } else { @@ -463,8 +470,13 @@ void ManagedThread::SetThreadPriority(int32_t prio) uint32_t ManagedThread::GetThreadPriority() const { +#ifdef PANDA_TARGET_UNIX ThreadId tid = GetId(); return os::thread::GetPriority(tid); +#else + auto hthread = GetCurrentThread(); + return os::thread::GetPriority(hthread); +#endif } void MTManagedThread::UpdateGCRoots() diff --git a/runtime/thread_pool.h b/runtime/thread_pool.h index 921a71cc84..318c95ee9f 100644 --- a/runtime/thread_pool.h +++ b/runtime/thread_pool.h @@ -257,7 +257,11 @@ private: LOG(FATAL, RUNTIME) << "Cannot create a worker thread"; } if (thread_name_ != nullptr) { +#ifdef PANDA_TARGET_UNIX int res = os::thread::SetThreadName(worker->native_handle(), thread_name_); +#else + int res = os::thread::SetThreadName(worker->get_id(), thread_name_); +#endif if (res != 0) { LOG(ERROR, RUNTIME) << "Failed to set a name for the worker thread"; } diff --git a/verification/job_queue/job_queue.cpp b/verification/job_queue/job_queue.cpp index 077fca503c..4eed26fa19 100644 --- a/verification/job_queue/job_queue.cpp +++ b/verification/job_queue/job_queue.cpp @@ -28,6 +28,7 @@ #include "libpandabase/os/thread.h" #include "macros.h" +#include namespace panda::verifier { @@ -123,7 +124,11 @@ void JobQueue::Stop(bool wait_queue_empty) void *retval = nullptr; for (size_t n = 0; n < num_verifier_threads; ++n) { +#ifdef PANDA_TARGET_UNIX os::thread::ThreadJoin((*verifier_thread_handle)[n], &retval); +#else + os::thread::ThreadJoin(reinterpret_cast((*verifier_thread_handle)[n]), &retval); +#endif } } -- Gitee From d5a6fd679af4a2b6ad2713311de64611dc9843db Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 19:54:54 +0800 Subject: [PATCH 21/26] Support 'mem' function on windows platform --- libpandabase/os/windows/mem.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libpandabase/os/windows/mem.cpp b/libpandabase/os/windows/mem.cpp index 7054e5ba0a..c1a519b30f 100644 --- a/libpandabase/os/windows/mem.cpp +++ b/libpandabase/os/windows/mem.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #define MAP_FAILED (reinterpret_cast(-1)) @@ -158,6 +159,17 @@ BytePtr MapFile(file::File file, uint32_t prot, uint32_t flags, size_t size, siz return BytePtr(static_cast(result) + offset, size, MmapDeleter); } +std::optional MakeMemReadExec(void *mem, size_t size) +{ + PDWORD old = nullptr; + // NOLINTNEXTLINE(hicpp-signed-bitwise) + int r = VirtualProtect(mem, size, MMAP_PROT_EXEC | MMAP_PROT_READ, old); + if (r != 0) { + return Error(errno); + } + return {}; +} + uint32_t GetPageSize() { constexpr size_t PAGE_SIZE = 4096; @@ -207,6 +219,15 @@ void *MapRWAnonymousWithAlignmentRaw(size_t size, size_t aligment_in_bytes, bool return reinterpret_cast(aligned_mem); } +uintptr_t AlignDownToPageSize(uintptr_t addr) +{ + SYSTEM_INFO sysInfo; + GetSystemInfo(&sysInfo); + const size_t SYS_PAGE_SIZE = sysInfo.dwPageSize; + addr &= ~(SYS_PAGE_SIZE - 1); + return addr; +} + void *AlignedAlloc(size_t alignment_in_bytes, size_t size) { size_t aligned_size = (size + alignment_in_bytes - 1) & ~(alignment_in_bytes - 1); @@ -234,4 +255,9 @@ std::optional TagAnonymousMemory([[maybe_unused]] const void *mem, [[mayb return {}; } +size_t GetNativeBytesFromMallinfo() +{ + return DEFAULT_NATIVE_BYTES_FROM_MALLINFO; +} + } // namespace panda::os::mem -- Gitee From fa282a20a739b9f4619749ea92aa9d97ee61a2a3 Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 19:55:33 +0800 Subject: [PATCH 22/26] Add needed modules in windows platform --- libpandabase/BUILD.gn | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libpandabase/BUILD.gn b/libpandabase/BUILD.gn index 838e61ed03..a99ab85448 100644 --- a/libpandabase/BUILD.gn +++ b/libpandabase/BUILD.gn @@ -40,6 +40,7 @@ if (is_mingw) { "$ark_root/libpandabase/mem/arena.cpp", "$ark_root/libpandabase/mem/arena_allocator.cpp", "$ark_root/libpandabase/mem/base_mem_stats.cpp", + "$ark_root/libpandabase/mem/code_allocator.cpp", "$ark_root/libpandabase/mem/mem_config.cpp", "$ark_root/libpandabase/mem/pool_manager.cpp", "$ark_root/libpandabase/mem/pool_map.cpp", @@ -58,6 +59,7 @@ if (is_mingw) { "$ark_root/libpandabase/utils/logger.cpp", "$ark_root/libpandabase/utils/utf.cpp", "$ark_root/libpandabase/utils/time.cpp", + "$ark_root/libpandabase/utils/type_converter.cpp", ] } else { libarkbase_sources = [ -- Gitee From b3a56e014a41639483b05e4cd37ecb3ea69c125d Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 19:56:41 +0800 Subject: [PATCH 23/26] Remove 'atomic' related functions on windows since it is not provided in MinGw --- libpandafile/panda_cache.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libpandafile/panda_cache.h b/libpandafile/panda_cache.h index 1be7b037ef..20164d627d 100644 --- a/libpandafile/panda_cache.h +++ b/libpandafile/panda_cache.h @@ -79,6 +79,7 @@ public: inline Method *GetMethodFromCache(File::EntityId id) const { +#ifdef PANDA_TARGET_UNIX uint32_t index = GetMethodIndex(id); auto *pair_ptr = reinterpret_cast *>(reinterpret_cast(&(method_cache_[index]))); @@ -87,11 +88,13 @@ public: if (pair.id_ == id) { return pair.ptr_; } +#endif return nullptr; } inline void SetMethodCache(File::EntityId id, Method *method) { +#ifdef PANDA_TARGET_UNIX MethodCachePair pair; pair.id_ = id; pair.ptr_ = method; @@ -100,10 +103,12 @@ public: reinterpret_cast *>(reinterpret_cast(&(method_cache_[index]))); TSAN_ANNOTATE_HAPPENS_BEFORE(pair_ptr); pair_ptr->store(pair, std::memory_order_release); +#endif } inline Field *GetFieldFromCache(File::EntityId id) const { +#ifdef PANDA_TARGET_UNIX uint32_t index = GetFieldIndex(id); auto *pair_ptr = reinterpret_cast *>(reinterpret_cast(&(field_cache_[index]))); @@ -112,11 +117,13 @@ public: if (pair.id_ == id) { return pair.ptr_; } +#endif return nullptr; } inline void SetFieldCache(File::EntityId id, Field *field) { +#ifdef PANDA_TARGET_UNIX uint32_t index = GetFieldIndex(id); auto *pair_ptr = reinterpret_cast *>(reinterpret_cast(&(field_cache_[index]))); @@ -125,10 +132,12 @@ public: pair.ptr_ = field; TSAN_ANNOTATE_HAPPENS_BEFORE(pair_ptr); pair_ptr->store(pair, std::memory_order_release); +#endif } inline Class *GetClassFromCache(File::EntityId id) const { +#ifdef PANDA_TARGET_UNIX uint32_t index = GetClassIndex(id); auto *pair_ptr = reinterpret_cast *>(reinterpret_cast(&(class_cache_[index]))); @@ -137,11 +146,13 @@ public: if (pair.id_ == id) { return pair.ptr_; } +#endif return nullptr; } inline void SetClassCache(File::EntityId id, Class *clazz) { +#ifdef PANDA_TARGET_UNIX ClassCachePair pair; pair.id_ = id; pair.ptr_ = clazz; @@ -150,11 +161,13 @@ public: reinterpret_cast *>(reinterpret_cast(&(class_cache_[index]))); TSAN_ANNOTATE_HAPPENS_BEFORE(pair_ptr); pair_ptr->store(pair, std::memory_order_release); +#endif } template bool EnumerateCachedClasses(const Callback &cb) { +#ifdef PANDA_TARGET_UNIX for (uint32_t i = 0; i < CLASS_CACHE_SIZE; i++) { auto *pair_ptr = reinterpret_cast *>(reinterpret_cast(&(class_cache_[i]))); @@ -166,6 +179,7 @@ public: } } } +#endif return true; } -- Gitee From a5dde43263dcf4a435d0cba54187e7909881766d Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 19:57:39 +0800 Subject: [PATCH 24/26] Remove 'os::native_stack' functions that windows not supported --- runtime/thread_manager.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/runtime/thread_manager.cpp b/runtime/thread_manager.cpp index 587d0a0880..162835b206 100644 --- a/runtime/thread_manager.cpp +++ b/runtime/thread_manager.cpp @@ -281,6 +281,7 @@ void ThreadManager::RegisterSensitiveThread() const void ThreadManager::DumpUnattachedThreads(std::ostream &os) { +#ifdef PANDA_TARGET_UNIX os::native_stack::DumpUnattachedThread dump; dump.InitKernelTidLists(); os::memory::LockHolder lock(thread_lock_); @@ -288,6 +289,7 @@ void ThreadManager::DumpUnattachedThreads(std::ostream &os) dump.AddTid(static_cast(thread->GetId())); } dump.Dump(os, Runtime::GetCurrent()->IsDumpNativeCrash(), nullptr); +#endif } MTManagedThread *ThreadManager::SuspendAndWaitThreadByInternalThreadId(uint32_t thread_id) -- Gitee From a1bd74635ccb94e3b23ce25003c3760cb31b3658 Mon Sep 17 00:00:00 2001 From: huangyu Date: Wed, 2 Mar 2022 20:00:05 +0800 Subject: [PATCH 25/26] Exclude profiler and signal_handler on windows --- runtime/BUILD.gn | 8 ++++++-- runtime/runtime.cpp | 6 ++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index ec35a4fba4..6c9096d9d7 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -75,7 +75,6 @@ ohos_static_library("libarkruntime_static") { "class_linker_extension.cpp", "coretypes/array.cpp", "coretypes/string.cpp", - "dprofiler/dprofiler.cpp", "dyn_class_linker_extension.cpp", "entrypoints/entrypoints.cpp", "exceptions.cpp", @@ -142,7 +141,6 @@ ohos_static_library("libarkruntime_static") { "profilesaver/profile_saver.cpp", "runtime.cpp", "runtime_helpers.cpp", - "signal_handler.cpp", "stack_walker.cpp", "string_table.cpp", "thread.cpp", @@ -158,6 +156,12 @@ ohos_static_library("libarkruntime_static") { "tooling/pt_thread.cpp", "vtable_builder.cpp", ] + if (is_linux) { + sources += [ + "dprofiler/dprofiler.cpp", + "signal_handler.cpp", + ] + } if (current_cpu == "arm") { sources += [ "arch/arm/interpreter_support.S", diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp index dc8a315510..d37c78cb4b 100644 --- a/runtime/runtime.cpp +++ b/runtime/runtime.cpp @@ -849,6 +849,7 @@ std::optional Runtime::CreateApplicationClassLinkerContext(std:: Expected Runtime::ExecutePandaFile(std::string_view filename, std::string_view entry_point, const std::vector &args) { +#ifdef PANDA_TARGET_UNIX if (options_.IsDistributedProfiling()) { // Create app name from path to executable file. std::string_view app_name = [](std::string_view path) -> std::string_view { @@ -857,6 +858,7 @@ Expected Runtime::ExecutePandaFile(std::string_view filenam }(filename); StartDProfiler(app_name); } +#endif auto ctx_err = CreateApplicationClassLinkerContext(filename, entry_point); if (ctx_err) { @@ -890,12 +892,15 @@ void Runtime::RegisterAppInfo(const PandaVector &code_paths, const return path.substr((pos == std::string_view::npos) ? 0 : (pos + 1)); }(profile_output_filename); +#ifdef PANDA_TARGET_UNIX StartDProfiler(app_name); +#endif // this is exactly the place where start the profile saver ProfileSaver::Start(profile_output_filename, code_paths, PandaString(app_name)); } +#ifdef PANDA_TARGET_UNIX int Runtime::StartDProfiler(std::string_view app_name) { if (dprofiler_ != nullptr) { @@ -906,6 +911,7 @@ int Runtime::StartDProfiler(std::string_view app_name) dprofiler_ = internal_allocator_->New(app_name, Runtime::GetCurrent()); return 0; } +#endif bool Runtime::StartDebugger(const std::string &library_path) { -- Gitee From 54c57675ba18c59d4919b0ae30806a86329e33b6 Mon Sep 17 00:00:00 2001 From: panzhenyu1 Date: Thu, 3 Mar 2022 16:21:35 +0800 Subject: [PATCH 26/26] for preview444 Change-Id: I9299bf24ca0a04162e84621f9edc182db0b1a122 --- libpandabase/macros.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libpandabase/macros.h b/libpandabase/macros.h index 13ba4f0ae6..2d85158d15 100644 --- a/libpandabase/macros.h +++ b/libpandabase/macros.h @@ -48,7 +48,11 @@ #endif // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) +#ifndef PANDA_TARGET_WINDOWS #define PANDA_PUBLIC_API __attribute__((visibility ("default"))) +#else +#define PANDA_PUBLIC_API __declspec(dllexport) +#endif // NOLINTNEXTLINE(cppcoreguidelines-macro-usage) #define MEMBER_OFFSET(T, F) offsetof(T, F) -- Gitee