diff --git a/OAT.xml b/OAT.xml
index e265949ea9ff6c2ab2d124352fe1ba30ef6adb14..c56f287617f0071dbaf08428cfe16f96967ccbf7 100644
--- a/OAT.xml
+++ b/OAT.xml
@@ -57,7 +57,9 @@ Note:If the text contains special characters, please escape them according to th
-
+
+
+
diff --git a/isa/gen_wrapper.sh b/isa/gen_wrapper.sh
index ba5c4ebdf94986a20d2a10ff4562a2282c691300..4e470348440359228fcf5ceac1c57c58a1b9f6e7 100644
--- a/isa/gen_wrapper.sh
+++ b/isa/gen_wrapper.sh
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
# 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.
@@ -14,7 +14,7 @@
set -e
-TOP=`pwd`
+TOP=$(pwd)
CMD=${TOP}/panda/isa/gen.rb
ISA_DATA=${TOP}/panda/isa/isa.yaml
ISA_REQUIRE=${TOP}/panda/isa/isapi.rb
@@ -30,7 +30,7 @@ if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
while getopts "O:D:R:I" arg
do
- case $arg in
+ case "$arg" in
O)
OUTPUT=${OPTARG}
;;
@@ -51,7 +51,7 @@ do
done
shift $(($OPTIND - 1))
-if [ ${HAS_ISA} ];then
+if [ "${HAS_ISA}" ];then
DATA=${ISA_DATA}
REQUIRE=${ISA_REQUIRE},${REQUIRE}
fi
diff --git a/libpandafile/file-inl.h b/libpandafile/file-inl.h
index 6727055bfcbc172c168490cba68707b09fd2cc6a..64211fd5efafde598a4026efb162e5ceefd0f511 100644
--- a/libpandafile/file-inl.h
+++ b/libpandafile/file-inl.h
@@ -27,7 +27,9 @@ inline File::StringData File::GetStringData(EntityId id) const
StringData str_data {};
auto sp = GetSpanFromId(id);
- str_data.utf16_length = panda_file::helpers::ReadULeb128(&sp);
+ auto tag_utf16_length = panda_file::helpers::ReadULeb128(&sp);
+ str_data.utf16_length = tag_utf16_length >> 1U;
+ str_data.is_ascii = static_cast(tag_utf16_length & 1U);
str_data.data = sp.data();
return str_data;
diff --git a/libpandafile/file.h b/libpandafile/file.h
index 50a25740bd2166daa38fe1aa4601a63ca357fc3f..cfa15a734c6c43eb0d107f1263727fe356b8f12d 100644
--- a/libpandafile/file.h
+++ b/libpandafile/file.h
@@ -72,8 +72,11 @@ public:
};
struct StringData {
- uint32_t utf16_length;
- const uint8_t *data;
+ StringData(uint32_t len, const uint8_t *d) : utf16_length(len), data(d), is_ascii(false) {}
+ StringData() = default;
+ uint32_t utf16_length; // NOLINT(misc-non-private-member-variables-in-classes)
+ const uint8_t *data; // NOLINT(misc-non-private-member-variables-in-classes)
+ bool is_ascii; // NOLINT(misc-non-private-member-variables-in-classes)
};
// NOLINTNEXTLINE(cppcoreguidelines-special-member-functions, hicpp-special-member-functions)
diff --git a/libpandafile/file_items.cpp b/libpandafile/file_items.cpp
index cbc8cf634bcb91edb88eb6359bece0b7ab081582..7f3e3b56040c3c98ca77396c1773aeedf63903cc 100644
--- a/libpandafile/file_items.cpp
+++ b/libpandafile/file_items.cpp
@@ -18,6 +18,7 @@
#include "macros.h"
#include "utils/bit_utils.h"
#include "utils/leb128.h"
+#include "utils/utf.h"
#include
#include
@@ -78,18 +79,32 @@ StringItem::StringItem(std::string str) : str_(std::move(str))
{
str_.push_back(0);
utf16_length_ = utf::MUtf8ToUtf16Size(utf::CStringAsMutf8(str_.data()));
+ is_ascii_ = 1;
+
+ for (auto c : str_) {
+ if (static_cast(c) > utf::MUTF8_1B_MAX) {
+ is_ascii_ = 0;
+ break;
+ }
+ }
}
size_t StringItem::CalculateSize() const
{
- return leb128::UnsignedEncodingSize(utf16_length_) + str_.size();
+ return leb128::UnsignedEncodingSize((utf16_length_ << 1U) | is_ascii_) + str_.size();
}
bool StringItem::Write(Writer *writer)
{
ASSERT(GetOffset() == writer->GetOffset());
- if (!writer->WriteUleb128(utf16_length_)) {
+ constexpr size_t max_string_length = 0x7fffffffU;
+ if (utf16_length_ > max_string_length) {
+ LOG(ERROR, PANDAFILE) << "Writing StringItem with size greater than 0x7fffffffU is not supported!";
+ return false;
+ }
+
+ if (!writer->WriteUleb128((utf16_length_ << 1U) | is_ascii_)) {
return false;
}
diff --git a/libpandafile/file_items.h b/libpandafile/file_items.h
index 077d7388d747fe0e87f7df994f27a60f77f02aea..27a09082b6919ff3451cc777ed77558a76a2b4e9 100644
--- a/libpandafile/file_items.h
+++ b/libpandafile/file_items.h
@@ -363,6 +363,7 @@ public:
private:
std::string str_;
size_t utf16_length_ {0};
+ size_t is_ascii_ {0};
};
class AnnotationItem;
diff --git a/libpandafile/literal_data_accessor-inl.h b/libpandafile/literal_data_accessor-inl.h
index e79d8d6faf7d0dd08b8d7977884abdc667ae809b..d683f872ca024b1c167621210663e6b873572b34 100644
--- a/libpandafile/literal_data_accessor-inl.h
+++ b/libpandafile/literal_data_accessor-inl.h
@@ -55,8 +55,7 @@ inline void LiteralDataAccessor::EnumerateLiteralVals(File::EntityId id, const C
value = static_cast(helpers::Read(&sp));
break;
case LiteralTag::STRING: {
- auto offset = static_cast(helpers::Read(&sp));
- value = panda_file_.GetStringData(File::EntityId(offset));
+ value = static_cast(helpers::Read(&sp));
break;
}
case LiteralTag::METHOD:
diff --git a/libpandafile/tests/file_item_container_test.cpp b/libpandafile/tests/file_item_container_test.cpp
index 5f86c7ee998239bf453805495cb026218bab5dd2..4c63f227291a6762525c48cfd1d3cadae6fd0813 100644
--- a/libpandafile/tests/file_item_container_test.cpp
+++ b/libpandafile/tests/file_item_container_test.cpp
@@ -35,6 +35,8 @@
#include
#include
+#include
+
#include
#include
@@ -142,7 +144,7 @@ TEST(ItemContainer, TestFileFormatVersionValid)
auto writer = FileWriter(file_name);
File::Header header;
- memset(&header, 0, sizeof(header));
+ (void)memset_s(&header, sizeof(header), 0, sizeof(header));
header.magic = File::MAGIC;
header.version = {0, 0, 0, 2};
header.file_size = sizeof(File::Header);
diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn
index e4d9aee1afb9fd2f460cf32f5d5dd5f47ba3b246..9f090f11e929f4465ad667b7724c98ebba32efdc 100644
--- a/runtime/BUILD.gn
+++ b/runtime/BUILD.gn
@@ -39,7 +39,25 @@ config("arkruntime_config") {
cflags_cc = [
"-Wno-invalid-offsetof",
"-Wno-unused-parameter",
- "-Wno-implicit-fallthrough",
+ ]
+}
+
+group("arkruntime_header_deps") {
+ deps = [
+ ":arkruntime_gen_intrinsics_intrinsics_gen_h",
+ ":arkruntime_gen_intrinsics_intrinsics_h",
+ ":arkruntime_gen_intrinsics_unimplemented_intrinsics-inl_cpp",
+ ":arkruntime_gen_intrinsics_yaml",
+ ":isa_gen_libarkruntime_interpreter-inl_gen_h",
+ ":isa_gen_libarkruntime_isa_constants_gen_h",
+ ":isa_gen_libarkruntime_unimplemented_handlers-inl_h",
+ ":libarkruntime_options_gen_h",
+ ":libarkruntime_shorty_values_h",
+ "$ark_root/verification/gen:isa_gen_verification_gen_abs_int_inl_gen_h",
+ "$ark_root/verification/gen:isa_gen_verification_gen_cflow_iterate_inl_gen_h",
+ "$ark_root/verification/gen:isa_gen_verification_gen_job_fill_gen_h",
+ "$ark_root/verification/gen:verification_abs_int_inl_compat_checks_h",
+ "$ark_root/verification/gen:verification_verifier_messages_h",
]
}
@@ -193,27 +211,14 @@ ohos_static_library("libarkruntime_static") {
]
deps = [
- ":arkruntime_gen_intrinsics_intrinsics_gen_h",
- ":arkruntime_gen_intrinsics_intrinsics_h",
- ":arkruntime_gen_intrinsics_unimplemented_intrinsics-inl_cpp",
- ":arkruntime_gen_intrinsics_yaml",
+ ":arkruntime_header_deps",
":arkruntime_interpreter_impl",
- ":isa_gen_libarkruntime_interpreter-inl_gen_h",
- ":isa_gen_libarkruntime_isa_constants_gen_h",
- ":isa_gen_libarkruntime_unimplemented_handlers-inl_h",
- ":libarkruntime_options_gen_h",
- ":libarkruntime_shorty_values_h",
"$ark_root/dprof:libdprof",
"$ark_root/libpandabase:libarkbase",
"$ark_root/libpandafile:libarkfile",
"$ark_root/libpandafile:libarkfile_type_gen_h",
"$ark_root/libziparchive:libarkziparchive",
"$ark_root/runtime/asm_defines:asm_defines_generator",
- "$ark_root/verification/gen:isa_gen_verification_gen_abs_int_inl_gen_h",
- "$ark_root/verification/gen:isa_gen_verification_gen_cflow_iterate_inl_gen_h",
- "$ark_root/verification/gen:isa_gen_verification_gen_job_fill_gen_h",
- "$ark_root/verification/gen:verification_abs_int_inl_compat_checks_h",
- "$ark_root/verification/gen:verification_verifier_messages_h",
sdk_libc_secshared_dep,
]
@@ -276,7 +281,6 @@ config("arkruntime_interpreter_impl_config") {
cflags_cc = [
"-Wno-invalid-offsetof",
"-Wno-unused-parameter",
- "-Wno-implicit-fallthrough",
]
defines = []
@@ -308,18 +312,9 @@ ohos_static_library("arkruntime_interpreter_impl") {
]
deps = [
- ":arkruntime_gen_intrinsics_intrinsics_gen_h",
- ":arkruntime_gen_intrinsics_intrinsics_h",
- ":arkruntime_gen_intrinsics_unimplemented_intrinsics-inl_cpp",
- ":arkruntime_gen_intrinsics_yaml",
- ":isa_gen_libarkruntime_interpreter-inl_gen_h",
- ":isa_gen_libarkruntime_isa_constants_gen_h",
- ":isa_gen_libarkruntime_unimplemented_handlers-inl_h",
- ":libarkruntime_options_gen_h",
- ":libarkruntime_shorty_values_h",
+ ":arkruntime_header_deps",
"$ark_root/libpandabase:libarkbase",
"$ark_root/libpandafile:libarkfile",
- "$ark_root/verification/gen:verification_verifier_messages_h",
]
}
diff --git a/runtime/asm_defines/BUILD.gn b/runtime/asm_defines/BUILD.gn
index 96edc1eba9e8516e263be0cf25881b33ffc3626e..be455aaeaf8fdebafb028138c6d3e9fe0a5fd5b2 100644
--- a/runtime/asm_defines/BUILD.gn
+++ b/runtime/asm_defines/BUILD.gn
@@ -35,7 +35,7 @@ ohos_static_library("asm_defines") {
output_extension = "S"
output_name = "libasm_defines"
deps = [
- "$ark_root/libpandafile:libarkfile_type_gen_h",
+ "$ark_root/libpandafile:libarkfile",
"$ark_root/runtime:arkruntime_gen_intrinsics_intrinsics_gen_h",
"$ark_root/runtime:arkruntime_gen_intrinsics_intrinsics_h",
"$ark_root/runtime:arkruntime_gen_intrinsics_unimplemented_intrinsics-inl_cpp",
diff --git a/runtime/class_linker.cpp b/runtime/class_linker.cpp
index 08fc3b2ef445ca23932011351414a44fc4c9a16c..f79fdada4e4b283b0b01d5f3f0f3915818cf44b7 100644
--- a/runtime/class_linker.cpp
+++ b/runtime/class_linker.cpp
@@ -496,7 +496,7 @@ static size_t LayoutFields(Class *klass, PandaList *tagged_fields, Pand
if (is_static) {
offset = klass->GetStaticFieldsOffset();
} else {
- offset = klass->GetBase() != nullptr ? klass->GetBase()->GetObjectSize() : ObjectHeader::ObjectHeaderSize();
+ offset = (klass->GetBase() != nullptr) ? klass->GetBase()->GetObjectSize() : ObjectHeader::ObjectHeaderSize();
}
if (!ref_fields->empty()) {
diff --git a/runtime/coretypes/string.cpp b/runtime/coretypes/string.cpp
index 17efb3b34bad464f7dfbf93899109195b2017371..d99b3032d6b5328c167f1c0938e7073aaa2a3607 100644
--- a/runtime/coretypes/string.cpp
+++ b/runtime/coretypes/string.cpp
@@ -71,9 +71,8 @@ String *String::CreateFromString(String *str, LanguageContext ctx, PandaVM *vm)
/* static */
String *String::CreateFromMUtf8(const uint8_t *mutf8_data, size_t mutf8_length, uint32_t utf16_length,
- LanguageContext ctx, PandaVM *vm, bool movable)
+ bool can_be_compressed, LanguageContext ctx, PandaVM *vm, bool movable)
{
- bool can_be_compressed = compressed_strings_enabled ? utf::IsMUtf8OnlySingleBytes(mutf8_data) : false;
auto string = AllocStringObject(utf16_length, can_be_compressed, ctx, vm, movable);
if (string == nullptr) {
return nullptr;
@@ -101,7 +100,15 @@ String *String::CreateFromMUtf8(const uint8_t *mutf8_data, size_t mutf8_length,
String *String::CreateFromMUtf8(const uint8_t *mutf8_data, uint32_t utf16_length, LanguageContext ctx, PandaVM *vm,
bool movable)
{
- return CreateFromMUtf8(mutf8_data, utf::Mutf8Size(mutf8_data), utf16_length, ctx, vm, movable);
+ bool can_be_compressed = CanBeCompressedMUtf8(mutf8_data);
+ return CreateFromMUtf8(mutf8_data, utf::Mutf8Size(mutf8_data), utf16_length, can_be_compressed, ctx, vm, movable);
+}
+
+/* static */
+String *String::CreateFromMUtf8(const uint8_t *mutf8_data, uint32_t utf16_length, bool can_be_compressed,
+ LanguageContext ctx, PandaVM *vm, bool movable)
+{
+ return CreateFromMUtf8(mutf8_data, utf::Mutf8Size(mutf8_data), utf16_length, can_be_compressed, ctx, vm, movable);
}
/* static */
@@ -109,7 +116,8 @@ String *String::CreateFromMUtf8(const uint8_t *mutf8_data, LanguageContext ctx,
{
size_t mutf8_length = utf::Mutf8Size(mutf8_data);
size_t utf16_length = utf::MUtf8ToUtf16Size(mutf8_data, mutf8_length);
- return CreateFromMUtf8(mutf8_data, mutf8_length, utf16_length, ctx, vm, movable);
+ bool can_be_compressed = CanBeCompressedMUtf8(mutf8_data);
+ return CreateFromMUtf8(mutf8_data, mutf8_length, utf16_length, can_be_compressed, ctx, vm, movable);
}
/* static */
@@ -397,6 +405,12 @@ bool String::CanBeCompressedMUtf8(const uint8_t *mutf8_data, uint32_t mutf8_leng
return is_compressed;
}
+/* static */
+bool String::CanBeCompressedMUtf8(const uint8_t *mutf8_data)
+{
+ return compressed_strings_enabled ? utf::IsMUtf8OnlySingleBytes(mutf8_data) : false;
+}
+
/* static */
bool String::CanBeCompressedUtf16(const uint16_t *utf16_data, uint32_t utf16_length, uint16_t non)
{
@@ -451,18 +465,27 @@ bool String::StringsAreEqual(String *str1, String *str2)
/* static */
bool String::StringsAreEqualMUtf8(String *str1, const uint8_t *mutf8_data, uint32_t utf16_length)
+{
+ if (str1->GetLength() != utf16_length) {
+ return false;
+ }
+ return StringsAreEqualMUtf8(str1, mutf8_data, utf16_length, CanBeCompressedMUtf8(mutf8_data));
+}
+
+/* static */
+bool String::StringsAreEqualMUtf8(String *str1, const uint8_t *mutf8_data, uint32_t utf16_length,
+ bool can_be_compressed)
{
bool result = true;
if (str1->GetLength() != utf16_length) {
result = false;
} else {
bool str1_can_be_compressed = !str1->IsUtf16();
- bool data2_can_be_compressed = compressed_strings_enabled ? utf::IsMUtf8OnlySingleBytes(mutf8_data) : false;
- if (str1_can_be_compressed != data2_can_be_compressed) {
+ if (str1_can_be_compressed != can_be_compressed) {
return false;
}
- ASSERT(str1_can_be_compressed == data2_can_be_compressed);
+ ASSERT(str1_can_be_compressed == can_be_compressed);
if (str1_can_be_compressed) {
Span data1(str1->GetDataMUtf8(), str1->GetLength());
Span data2(mutf8_data, utf16_length);
@@ -608,7 +631,12 @@ uint32_t String::ComputeHashcode()
/* static */
uint32_t String::ComputeHashcodeMutf8(const uint8_t *mutf8_data, uint32_t utf16_length)
{
- bool can_be_compressed = compressed_strings_enabled ? utf::IsMUtf8OnlySingleBytes(mutf8_data) : false;
+ return ComputeHashcodeMutf8(mutf8_data, utf16_length, CanBeCompressedMUtf8(mutf8_data));
+}
+
+/* static */
+uint32_t String::ComputeHashcodeMutf8(const uint8_t *mutf8_data, uint32_t utf16_length, bool can_be_compressed)
+{
uint32_t hash;
if (can_be_compressed) {
hash = ComputeHashForMutf8(mutf8_data);
diff --git a/runtime/include/coretypes/string.h b/runtime/include/coretypes/string.h
index 5d673d931a5a574f1d32221a163a7edf0f70adfa..6168fabb58b7adeb7ce4a17f991de933a06086a9 100644
--- a/runtime/include/coretypes/string.h
+++ b/runtime/include/coretypes/string.h
@@ -37,6 +37,9 @@ public:
}
static String *CreateFromMUtf8(const uint8_t *mutf8_data, size_t mutf8_length, uint32_t utf16_length,
+ bool can_be_compressed, LanguageContext ctx, PandaVM *vm, bool movable = true);
+
+ static String *CreateFromMUtf8(const uint8_t *mutf8_data, uint32_t utf16_length, bool can_be_compressed,
LanguageContext ctx, PandaVM *vm, bool movable = true);
static String *CreateFromMUtf8(const uint8_t *mutf8_data, uint32_t utf16_length, LanguageContext ctx, PandaVM *vm,
@@ -235,11 +238,14 @@ public:
* Compares strings by bytes. It doesn't check canonical unicode equivalence.
*/
static bool StringsAreEqualMUtf8(String *str1, const uint8_t *mutf8_data, uint32_t utf16_length);
+ static bool StringsAreEqualMUtf8(String *str1, const uint8_t *mutf8_data, uint32_t utf16_length,
+ bool can_be_compressed);
/**
* Compares strings by bytes. It doesn't check canonical unicode equivalence.
*/
static bool StringsAreEqualUtf16(String *str1, const uint16_t *utf16_data, uint32_t utf16_data_length);
static String *DoReplace(String *src, uint16_t old_c, uint16_t new_c, LanguageContext ctx, PandaVM *vm);
+ static uint32_t ComputeHashcodeMutf8(const uint8_t *mutf8_data, uint32_t length, bool can_be_compressed);
static uint32_t ComputeHashcodeMutf8(const uint8_t *mutf8_data, uint32_t length);
static uint32_t ComputeHashcodeUtf16(uint16_t *utf16_data, uint32_t length);
@@ -256,6 +262,8 @@ public:
static String *FastSubString(String *src, uint32_t start, uint32_t utf16_length, LanguageContext ctx,
PandaVM *vm = nullptr);
+ static bool CanBeCompressedMUtf8(const uint8_t *mutf8_data);
+
protected:
void SetLength(uint32_t length, bool compressed = false)
{
diff --git a/runtime/mark_word.h b/runtime/mark_word.h
index a2dbf7c57501211677ba74ecc99cf74f4fa62091..557216db9c39e0ab83cce579115f50b6f40c1397 100644
--- a/runtime/mark_word.h
+++ b/runtime/mark_word.h
@@ -120,7 +120,7 @@ public:
// If we don't have Hash inside an object header, thisThread constant shouldn't be used
HASH_SIZE = (CONFIG_HASH_STATUS_SIZE != 0UL)
? 0UL
- : CONFIG_MARK_WORD_BIT_SIZE - STATUS_SIZE - GC_STATUS_SIZE - RB_STATUS_SIZE,
+ : (CONFIG_MARK_WORD_BIT_SIZE - STATUS_SIZE - GC_STATUS_SIZE - RB_STATUS_SIZE),
FORWARDING_ADDRESS_SIZE = CONFIG_MARK_WORD_BIT_SIZE - STATUS_SIZE - HASH_STATUS_SIZE,
// Unlocked state masks and shifts
diff --git a/runtime/mem/rendezvous.cpp b/runtime/mem/rendezvous.cpp
index ed2be10a15d856010fa0a508c0e1bb387bfc2c2e..7aa07ca0017787a20ab8ab39a2d4cead28a4d553 100644
--- a/runtime/mem/rendezvous.cpp
+++ b/runtime/mem/rendezvous.cpp
@@ -43,18 +43,6 @@ void Rendezvous::SafepointEnd()
LOG(DEBUG, GC) << "Rendezvous: SafepointEnd exit";
}
-ScopedSuspendAllThreads::ScopedSuspendAllThreads(Rendezvous *rendezvous) : rendezvous_(rendezvous)
-{
- ASSERT(rendezvous_ != nullptr);
- rendezvous_->SafepointBegin();
-}
-
-ScopedSuspendAllThreads::~ScopedSuspendAllThreads()
-{
- ASSERT(rendezvous_ != nullptr);
- rendezvous_->SafepointEnd();
-}
-
ScopedSuspendAllThreadsRunning::ScopedSuspendAllThreadsRunning(Rendezvous *rendezvous) : rendezvous_(rendezvous)
{
ASSERT(rendezvous_ != nullptr);
diff --git a/runtime/mem/rendezvous.h b/runtime/mem/rendezvous.h
index 21316a4d0c8dbcf3f88b9ac7ce4f84cc7b89caea..08c2a2edcca2f7c791c5701a5b18dd2351e571fe 100644
--- a/runtime/mem/rendezvous.h
+++ b/runtime/mem/rendezvous.h
@@ -61,8 +61,16 @@ private:
class ScopedSuspendAllThreads {
public:
- explicit ScopedSuspendAllThreads(Rendezvous *rendezvous) ACQUIRE(*Locks::mutator_lock);
- ~ScopedSuspendAllThreads() RELEASE(*Locks::mutator_lock);
+ explicit ScopedSuspendAllThreads(Rendezvous *rendezvous) ACQUIRE(*Locks::mutator_lock) : rendezvous_(rendezvous)
+ {
+ ASSERT(rendezvous_ != nullptr);
+ rendezvous_->SafepointBegin();
+ }
+ ~ScopedSuspendAllThreads() RELEASE(*Locks::mutator_lock)
+ {
+ ASSERT(rendezvous_ != nullptr);
+ rendezvous_->SafepointEnd();
+ }
NO_COPY_SEMANTIC(ScopedSuspendAllThreads);
NO_MOVE_SEMANTIC(ScopedSuspendAllThreads);
diff --git a/runtime/runtime.cpp b/runtime/runtime.cpp
index 893adc8d42d373b4b14ba75f623cc1b8b0b6d47b..e0e1a673a17bd7e610b42ac6a81a6a17a9b3ddfd 100644
--- a/runtime/runtime.cpp
+++ b/runtime/runtime.cpp
@@ -866,7 +866,7 @@ Expected Runtime::ExecutePandaFile(std::string_view filenam
// Create app name from path to executable file.
std::string_view app_name = [](std::string_view path) -> std::string_view {
auto pos = path.find_last_of('/');
- return path.substr(pos == std::string_view::npos ? 0 : pos + 1);
+ return path.substr((pos == std::string_view::npos) ? 0 : (pos + 1));
}(filename);
StartDProfiler(app_name);
}
@@ -900,7 +900,7 @@ void Runtime::RegisterAppInfo(const PandaVector &code_paths, const
}
std::string_view app_name = [](std::string_view path) -> std::string_view {
auto pos = path.find_last_of('/');
- return path.substr(pos == std::string_view::npos ? 0 : pos + 1);
+ return path.substr((pos == std::string_view::npos) ? 0 : (pos + 1));
}(profile_output_filename);
StartDProfiler(app_name);
diff --git a/runtime/string_table.cpp b/runtime/string_table.cpp
index 7f52166fbdf2dbcf747d429dd30d05596c6f96c1..6098d369cfa66d2de3303ebebebacff74fc3b1c7 100644
--- a/runtime/string_table.cpp
+++ b/runtime/string_table.cpp
@@ -24,9 +24,10 @@ namespace panda {
coretypes::String *StringTable::GetOrInternString(const uint8_t *mutf8_data, uint32_t utf16_length, LanguageContext ctx)
{
- auto *str = internal_table_.GetString(mutf8_data, utf16_length, ctx);
+ bool can_be_compressed = coretypes::String::CanBeCompressedMUtf8(mutf8_data);
+ auto *str = internal_table_.GetString(mutf8_data, utf16_length, can_be_compressed, ctx);
if (str == nullptr) {
- str = table_.GetOrInternString(mutf8_data, utf16_length, ctx);
+ str = table_.GetOrInternString(mutf8_data, utf16_length, can_be_compressed, ctx);
}
return str;
}
@@ -54,7 +55,7 @@ coretypes::String *StringTable::GetOrInternInternalString(const panda_file::File
LanguageContext ctx)
{
auto data = pf.GetStringData(id);
- coretypes::String *str = table_.GetString(data.data, data.utf16_length, ctx);
+ coretypes::String *str = table_.GetString(data.data, data.utf16_length, data.is_ascii, ctx);
if (str != nullptr) {
return str;
}
@@ -77,13 +78,13 @@ size_t StringTable::Size()
}
coretypes::String *StringTable::Table::GetString(const uint8_t *utf8_data, uint32_t utf16_length,
- [[maybe_unused]] LanguageContext ctx)
+ bool can_be_compressed, [[maybe_unused]] LanguageContext ctx)
{
- uint32_t hash_code = coretypes::String::ComputeHashcodeMutf8(utf8_data, utf16_length);
+ uint32_t hash_code = coretypes::String::ComputeHashcodeMutf8(utf8_data, utf16_length, can_be_compressed);
os::memory::ReadLockHolder holder(table_lock_);
for (auto it = table_.find(hash_code); it != table_.end(); it++) {
auto found_string = it->second;
- if (coretypes::String::StringsAreEqualMUtf8(found_string, utf8_data, utf16_length)) {
+ if (coretypes::String::StringsAreEqualMUtf8(found_string, utf8_data, utf16_length, can_be_compressed)) {
return found_string;
}
}
@@ -140,15 +141,16 @@ coretypes::String *StringTable::Table::InternString(coretypes::String *string, [
}
coretypes::String *StringTable::Table::GetOrInternString(const uint8_t *mutf8_data, uint32_t utf16_length,
- LanguageContext ctx)
+ bool can_be_compressed, LanguageContext ctx)
{
- coretypes::String *result = GetString(mutf8_data, utf16_length, ctx);
+ coretypes::String *result = GetString(mutf8_data, utf16_length, can_be_compressed, ctx);
if (result != nullptr) {
return result;
}
// Even if this string is not inserted, it should get removed during GC
- result = coretypes::String::CreateFromMUtf8(mutf8_data, utf16_length, ctx, Runtime::GetCurrent()->GetPandaVM());
+ result = coretypes::String::CreateFromMUtf8(mutf8_data, utf16_length, can_be_compressed, ctx,
+ Runtime::GetCurrent()->GetPandaVM());
result = InternString(result, ctx);
@@ -233,15 +235,15 @@ size_t StringTable::Table::Size()
}
coretypes::String *StringTable::InternalTable::GetOrInternString(const uint8_t *mutf8_data, uint32_t utf16_length,
- LanguageContext ctx)
+ bool can_be_compressed, LanguageContext ctx)
{
- coretypes::String *result = GetString(mutf8_data, utf16_length, ctx);
+ coretypes::String *result = GetString(mutf8_data, utf16_length, can_be_compressed, ctx);
if (result != nullptr) {
return result;
}
- result =
- coretypes::String::CreateFromMUtf8(mutf8_data, utf16_length, ctx, Runtime::GetCurrent()->GetPandaVM(), false);
+ result = coretypes::String::CreateFromMUtf8(mutf8_data, utf16_length, can_be_compressed, ctx,
+ Runtime::GetCurrent()->GetPandaVM(), false);
return InternStringNonMovable(result, ctx);
}
@@ -262,12 +264,12 @@ coretypes::String *StringTable::InternalTable::GetOrInternString(const panda_fil
panda_file::File::EntityId id, LanguageContext ctx)
{
auto data = pf.GetStringData(id);
- coretypes::String *result = GetString(data.data, data.utf16_length, ctx);
+ coretypes::String *result = GetString(data.data, data.utf16_length, data.is_ascii, ctx);
if (result != nullptr) {
return result;
}
- result = coretypes::String::CreateFromMUtf8(data.data, data.utf16_length, ctx, Runtime::GetCurrent()->GetPandaVM(),
- false);
+ result = coretypes::String::CreateFromMUtf8(data.data, data.utf16_length, data.is_ascii, ctx,
+ Runtime::GetCurrent()->GetPandaVM(), false);
result = InternStringNonMovable(result, ctx);
// Update cache.
diff --git a/runtime/string_table.h b/runtime/string_table.h
index 40a293ce3243fe8cd00721d2b8e1a545b9f388ed..76f3d6d572e32b15a179bca4e5e10c18e16a588e 100644
--- a/runtime/string_table.h
+++ b/runtime/string_table.h
@@ -69,7 +69,7 @@ protected:
virtual ~Table() = default;
virtual coretypes::String *GetOrInternString(const uint8_t *mutf8_data, uint32_t utf16_length,
- LanguageContext ctx);
+ bool can_be_compressed, LanguageContext ctx);
virtual coretypes::String *GetOrInternString(const uint16_t *utf16_data, uint32_t utf16_length,
LanguageContext ctx);
coretypes::String *GetOrInternString(coretypes::String *string, LanguageContext ctx);
@@ -79,7 +79,8 @@ protected:
size_t Size();
- coretypes::String *GetString(const uint8_t *utf8_data, uint32_t utf16_length, LanguageContext ctx);
+ coretypes::String *GetString(const uint8_t *utf8_data, uint32_t utf16_length, bool can_be_compressed,
+ LanguageContext ctx);
coretypes::String *GetString(const uint16_t *utf16_data, uint32_t utf16_length, LanguageContext ctx);
coretypes::String *GetString(coretypes::String *string, LanguageContext ctx);
@@ -107,7 +108,7 @@ protected:
}
~InternalTable() override = default;
- coretypes::String *GetOrInternString(const uint8_t *mutf8_data, uint32_t utf16_length,
+ coretypes::String *GetOrInternString(const uint8_t *mutf8_data, uint32_t utf16_length, bool can_be_compressed,
LanguageContext ctx) override;
coretypes::String *GetOrInternString(const uint16_t *utf16_data, uint32_t utf16_length,
diff --git a/scripts/extra/build.sh b/scripts/extra/build.sh
index e3b567a10b26dcc2f92b68060f7a43d2f8b7f02b..979541c32d7cf2e5fc186205ea3c739635e02e57 100755
--- a/scripts/extra/build.sh
+++ b/scripts/extra/build.sh
@@ -1,4 +1,4 @@
-#!/bin/bash -ex
+#!/bin/bash
# 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.
@@ -12,8 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+set -ex
-if [[ ${BUILD_TOOL} = "ninja" ]]; then
+if [[ "${BUILD_TOOL}" = "ninja" ]]; then
GENERATOR="Ninja"
BUILD_STR="ninja -k1"
else
diff --git a/scripts/memdump.py b/scripts/memdump.py
index 0cea92660c0e4a66c440908c9b9edd9de7f2a880..e8fd40163e6d865accdfcb118da2ef462b5b7b55 100755
--- a/scripts/memdump.py
+++ b/scripts/memdump.py
@@ -1,4 +1,4 @@
-#!/bin/python3
+#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");