Commit 1399fd8a authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[wasm] Remove dummy {WasmCode} constructor.

R=clemensh@chromium.org

Change-Id: Ic374aaf222a20b5fffe95ffe22c14ff998fca7fd
Reviewed-on: https://chromium-review.googlesource.com/973227
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52113}
parent b73cbb32
......@@ -32,6 +32,16 @@ namespace wasm {
namespace {
// Binary predicate to perform lookups in {NativeModule::owned_code_} with a
// given address into a code object. Use with {std::upper_bound} for example.
struct WasmCodeUniquePtrComparator {
bool operator()(Address pc, const std::unique_ptr<WasmCode>& code) const {
DCHECK_NOT_NULL(pc);
DCHECK_NOT_NULL(code);
return pc < code->instructions().start();
}
};
#if V8_TARGET_ARCH_X64
#define __ masm->
constexpr bool kModuleCanAllocateMoreMemory = false;
......@@ -355,7 +365,8 @@ WasmCode* NativeModule::AddOwnedCode(
// even if we end up with segmented memory, we may end up only with a few
// large moves - if, for example, a new segment is below the current ones.
auto insert_before = std::upper_bound(owned_code_.begin(), owned_code_.end(),
code, owned_code_comparer_);
ret->instructions().start(),
WasmCodeUniquePtrComparator());
owned_code_.insert(insert_before, std::move(code));
if (flush_icache) {
Assembler::FlushICache(ret->instructions().start(),
......@@ -649,10 +660,8 @@ Address NativeModule::AllocateForCode(size_t size) {
WasmCode* NativeModule::Lookup(Address pc) {
if (owned_code_.empty()) return nullptr;
// Make a fake WasmCode temp, to look into owned_code_
std::unique_ptr<WasmCode> temp(new WasmCode(pc));
auto iter = std::upper_bound(owned_code_.begin(), owned_code_.end(), temp,
owned_code_comparer_);
auto iter = std::upper_bound(owned_code_.begin(), owned_code_.end(), pc,
WasmCodeUniquePtrComparator());
if (iter == owned_code_.begin()) return nullptr;
--iter;
WasmCode* candidate = (*iter).get();
......
......@@ -143,10 +143,6 @@ class V8_EXPORT_PRIVATE WasmCode final {
private:
friend class NativeModule;
friend class NativeModuleDeserializer;
// A constructor used just for implementing Lookup.
WasmCode(Address pc) : instructions_(pc, 0), index_(Nothing<uint32_t>()) {}
WasmCode(Vector<byte> instructions,
std::unique_ptr<const byte[]>&& reloc_info, size_t reloc_size,
......@@ -172,9 +168,6 @@ class V8_EXPORT_PRIVATE WasmCode final {
DCHECK_LE(handler_table_offset, instructions.size());
}
WasmCode(const WasmCode&) = delete;
WasmCode& operator=(const WasmCode&) = delete;
Vector<byte> instructions_;
std::unique_ptr<const byte[]> reloc_info_;
size_t reloc_size_ = 0;
......@@ -191,6 +184,8 @@ class V8_EXPORT_PRIVATE WasmCode final {
intptr_t trap_handler_index_ = -1;
std::shared_ptr<ProtectedInstructions> protected_instructions_;
Tier tier_;
DISALLOW_COPY_AND_ASSIGN(WasmCode);
};
// Return a textual description of the kind.
......@@ -270,18 +265,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
friend class NativeModuleDeserializer;
friend class NativeModuleModificationScope;
struct WasmCodeUniquePtrComparer {
bool operator()(const std::unique_ptr<WasmCode>& a,
const std::unique_ptr<WasmCode>& b) {
DCHECK(a);
DCHECK(b);
return a->instructions().start() < b->instructions().start();
}
};
static base::AtomicNumber<size_t> next_id_;
NativeModule(const NativeModule&) = delete;
NativeModule& operator=(const NativeModule&) = delete;
NativeModule(uint32_t num_functions, uint32_t num_imports,
bool can_request_more, VirtualMemory* vmem,
WasmCodeManager* code_manager);
......@@ -307,10 +291,10 @@ class V8_EXPORT_PRIVATE NativeModule final {
Address GetLocalAddressFor(Handle<Code>);
Address CreateTrampolineTo(Handle<Code>);
// Holds all allocated code objects, is maintained to be in ascending order
// according to the codes instruction start address to allow lookups.
std::vector<std::unique_ptr<WasmCode>> owned_code_;
WasmCodeUniquePtrComparer owned_code_comparer_;
std::vector<WasmCode*> code_table_;
uint32_t num_imported_functions_;
......@@ -333,6 +317,8 @@ class V8_EXPORT_PRIVATE NativeModule final {
bool can_request_more_memory_;
bool is_executable_ = false;
int modification_scope_depth_ = 0;
DISALLOW_COPY_AND_ASSIGN(NativeModule);
};
class V8_EXPORT_PRIVATE WasmCodeManager final {
......@@ -359,8 +345,6 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
private:
friend class NativeModule;
WasmCodeManager(const WasmCodeManager&) = delete;
WasmCodeManager& operator=(const WasmCodeManager&) = delete;
void TryAllocate(size_t size, VirtualMemory*, void* hint = nullptr);
bool Commit(Address, size_t);
// Currently, we uncommit a whole module, so all we need is account
......@@ -381,6 +365,8 @@ class V8_EXPORT_PRIVATE WasmCodeManager final {
// TODO(mtrofin): remove the dependency on isolate.
v8::Isolate* isolate_;
DISALLOW_COPY_AND_ASSIGN(WasmCodeManager);
};
// Within the scope, the native_module is writable and not executable.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment