[VM runtime] Follow up to new NativeEntryData class.

Demote newly introduced VM class NativeEntryData from a VM instance class
to a simple TypedData wrapper class.

Change-Id: I44aacee33500c93eb283d2d349cd7a24dd94de65
Reviewed-on: https://dart-review.googlesource.com/74323
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
This commit is contained in:
Régis Crelier
2018-09-12 18:49:06 +00:00
committed by commit-bot@chromium.org
parent 7442bac571
commit a6a48f2e52
16 changed files with 164 additions and 153 deletions
+10 -5
View File
@@ -2,10 +2,13 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/globals.h"
#if !defined(DART_PRECOMPILED_RUNTIME)
#include "vm/code_patcher.h"
#include "vm/instructions_kbc.h"
#include "vm/object.h"
#include "vm/native_entry.h"
namespace dart {
@@ -14,8 +17,8 @@ void KBCPatcher::PatchNativeCallAt(uword return_address,
NativeFunction function,
NativeFunctionWrapper trampoline) {
ASSERT(bytecode.ContainsInstructionAt(return_address));
const NativeEntryData& native_entry_data = NativeEntryData::Handle(
KBCNativeCallPattern::GetNativeEntryDataAt(return_address, bytecode));
NativeEntryData native_entry_data(TypedData::Handle(
KBCNativeCallPattern::GetNativeEntryDataAt(return_address, bytecode)));
native_entry_data.set_trampoline(trampoline);
native_entry_data.set_native_function(function);
}
@@ -24,10 +27,12 @@ NativeFunctionWrapper KBCPatcher::GetNativeCallAt(uword return_address,
const Code& bytecode,
NativeFunction* function) {
ASSERT(bytecode.ContainsInstructionAt(return_address));
const NativeEntryData& native_entry_data = NativeEntryData::Handle(
KBCNativeCallPattern::GetNativeEntryDataAt(return_address, bytecode));
NativeEntryData native_entry_data(TypedData::Handle(
KBCNativeCallPattern::GetNativeEntryDataAt(return_address, bytecode)));
*function = native_entry_data.native_function();
return native_entry_data.trampoline();
}
} // namespace dart
#endif // !defined(DART_PRECOMPILED_RUNTIME)
@@ -635,9 +635,8 @@ void BytecodeMetadataHelper::ReadExceptionsTable(const Code& bytecode) {
}
}
RawNativeEntryData* BytecodeMetadataHelper::NativeEntry(
const Function& function,
const String& external_name) {
RawTypedData* BytecodeMetadataHelper::NativeEntry(const Function& function,
const String& external_name) {
Zone* zone = helper_->zone_;
MethodRecognizer::Kind kind = MethodRecognizer::RecognizeKind(function);
// This list of recognized methods must be kept in sync with the list of
@@ -697,13 +696,7 @@ RawNativeEntryData* BytecodeMetadataHelper::NativeEntry(
}
argc_tag = NativeArguments::ComputeArgcTag(function);
}
const NativeEntryData& native_entry =
NativeEntryData::Handle(zone, NativeEntryData::New());
native_entry.set_kind(kind);
native_entry.set_trampoline(trampoline);
native_entry.set_native_function(native_function);
native_entry.set_argc_tag(argc_tag);
return native_entry.raw();
return NativeEntryData::New(kind, trampoline, native_function, argc_tag);
}
} // namespace kernel
@@ -32,8 +32,8 @@ class BytecodeMetadataHelper : public MetadataHelper {
intptr_t from_index);
RawCode* ReadBytecode(const ObjectPool& pool);
void ReadExceptionsTable(const Code& bytecode);
RawNativeEntryData* NativeEntry(const Function& function,
const String& external_name);
RawTypedData* NativeEntry(const Function& function,
const String& external_name);
TypeTranslator& type_translator_;
ActiveClass* const active_class_;
+11 -6
View File
@@ -2,17 +2,19 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#include "vm/globals.h"
#if !defined(DART_PRECOMPILED_RUNTIME)
#include "vm/instructions.h"
#include "vm/instructions_kbc.h"
#include "vm/constants_kbc.h"
#include "vm/object.h"
#include "vm/native_entry.h"
namespace dart {
RawNativeEntryData* KBCNativeCallPattern::GetNativeEntryDataAt(
uword pc,
const Code& bytecode) {
RawTypedData* KBCNativeCallPattern::GetNativeEntryDataAt(uword pc,
const Code& bytecode) {
ASSERT(bytecode.ContainsInstructionAt(pc));
const uword call_pc = pc - sizeof(KBCInstr);
KBCInstr call_instr = KernelBytecode::At(call_pc);
@@ -20,11 +22,14 @@ RawNativeEntryData* KBCNativeCallPattern::GetNativeEntryDataAt(
KernelBytecode::kNativeCall);
intptr_t native_entry_data_pool_index = KernelBytecode::DecodeD(call_instr);
const ObjectPool& object_pool = ObjectPool::Handle(bytecode.GetObjectPool());
NativeEntryData& native_entry_data = NativeEntryData::Handle();
TypedData& native_entry_data = TypedData::Handle();
native_entry_data ^= object_pool.ObjectAt(native_entry_data_pool_index);
// Native calls to recognized functions should never be patched.
ASSERT(native_entry_data.kind() == MethodRecognizer::kUnknown);
ASSERT(NativeEntryData(native_entry_data).kind() ==
MethodRecognizer::kUnknown);
return native_entry_data.raw();
}
} // namespace dart
#endif // !defined(DART_PRECOMPILED_RUNTIME)
+6 -2
View File
@@ -6,16 +6,20 @@
#ifndef RUNTIME_VM_INSTRUCTIONS_KBC_H_
#define RUNTIME_VM_INSTRUCTIONS_KBC_H_
#include "vm/globals.h"
#if !defined(DART_PRECOMPILED_RUNTIME)
#include "vm/object.h"
namespace dart {
class KBCNativeCallPattern : public AllStatic {
public:
static RawNativeEntryData* GetNativeEntryDataAt(uword pc,
const Code& bytecode);
static RawTypedData* GetNativeEntryDataAt(uword pc, const Code& bytecode);
};
#endif // !defined(DART_PRECOMPILED_RUNTIME)
} // namespace dart
#endif // RUNTIME_VM_INSTRUCTIONS_KBC_H_
+5 -6
View File
@@ -2489,9 +2489,8 @@ RawObject* Interpreter::Call(RawFunction* function,
{
BYTECODE(NativeCall, __D);
RawNativeEntryData* native_entry =
static_cast<RawNativeEntryData*>(LOAD_CONSTANT(rD));
MethodRecognizer::Kind kind = native_entry->ptr()->kind_;
RawTypedData* data = static_cast<RawTypedData*>(LOAD_CONSTANT(rD));
MethodRecognizer::Kind kind = NativeEntryData::GetKind(data);
switch (kind) {
case MethodRecognizer::kObjectEquals: {
SP[-1] = SP[-1] == SP[0] ? Bool::True().raw() : Bool::False().raw();
@@ -2630,9 +2629,9 @@ RawObject* Interpreter::Call(RawFunction* function,
*--SP = null_value;
} break;
default: {
NativeFunctionWrapper trampoline = native_entry->ptr()->trampoline_;
NativeFunction function = native_entry->ptr()->native_function_;
intptr_t argc_tag = native_entry->ptr()->argc_tag_;
NativeFunctionWrapper trampoline = NativeEntryData::GetTrampoline(data);
NativeFunction function = NativeEntryData::GetNativeFunction(data);
intptr_t argc_tag = NativeEntryData::GetArgcTag(data);
const intptr_t num_arguments =
NativeArguments::ArgcBits::decode(argc_tag);
-1
View File
@@ -213,7 +213,6 @@ class NativeArguments {
friend class Api;
friend class BootstrapNatives;
friend class Interpreter;
friend class NativeEntryData;
friend class Simulator;
// Allow simulator and interpreter to create NativeArguments in reverse order
+79
View File
@@ -283,6 +283,7 @@ void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
#if defined(DEBUG) && !defined(TARGET_ARCH_DBC)
NativeFunction current_function = NULL;
if (caller_frame->is_interpreted()) {
#if !defined(DART_PRECOMPILED_RUNTIME)
ASSERT(FLAG_enable_interpreter);
NativeFunctionWrapper current_trampoline = KBCPatcher::GetNativeCallAt(
caller_frame->pc(), code, &current_function);
@@ -291,6 +292,9 @@ void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
ASSERT(current_trampoline == &BootstrapNativeCallWrapper ||
current_trampoline == &AutoScopeNativeCallWrapper ||
current_trampoline == &NoScopeNativeCallWrapper);
#else
UNREACHABLE();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
} else {
const Code& current_trampoline =
Code::Handle(zone, CodePatcher::GetNativeCallAt(
@@ -324,6 +328,7 @@ void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
patch_target_function, trampoline);
#else
if (caller_frame->is_interpreted()) {
#if !defined(DART_PRECOMPILED_RUNTIME)
ASSERT(FLAG_enable_interpreter);
NativeFunctionWrapper trampoline;
if (is_bootstrap_native) {
@@ -335,6 +340,9 @@ void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
}
KBCPatcher::PatchNativeCallAt(caller_frame->pc(), code,
patch_target_function, trampoline);
#else
UNREACHABLE();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
} else {
Code& trampoline = Code::Handle(zone);
if (is_bootstrap_native) {
@@ -378,4 +386,75 @@ void NativeEntry::LinkNativeCall(Dart_NativeArguments args) {
}
}
#if !defined(DART_PRECOMPILED_RUNTIME)
// Note: not GC safe. Use with care.
NativeEntryData::Payload* NativeEntryData::FromTypedArray(RawTypedData* data) {
return reinterpret_cast<Payload*>(data->ptr()->data());
}
MethodRecognizer::Kind NativeEntryData::kind() const {
return FromTypedArray(data_.raw())->kind;
}
void NativeEntryData::set_kind(MethodRecognizer::Kind value) const {
FromTypedArray(data_.raw())->kind = value;
}
MethodRecognizer::Kind NativeEntryData::GetKind(RawTypedData* data) {
return FromTypedArray(data)->kind;
}
NativeFunctionWrapper NativeEntryData::trampoline() const {
return FromTypedArray(data_.raw())->trampoline;
}
void NativeEntryData::set_trampoline(NativeFunctionWrapper value) const {
FromTypedArray(data_.raw())->trampoline = value;
}
NativeFunctionWrapper NativeEntryData::GetTrampoline(RawTypedData* data) {
return FromTypedArray(data)->trampoline;
}
NativeFunction NativeEntryData::native_function() const {
return FromTypedArray(data_.raw())->native_function;
}
void NativeEntryData::set_native_function(NativeFunction value) const {
FromTypedArray(data_.raw())->native_function = value;
}
NativeFunction NativeEntryData::GetNativeFunction(RawTypedData* data) {
return FromTypedArray(data)->native_function;
}
intptr_t NativeEntryData::argc_tag() const {
return FromTypedArray(data_.raw())->argc_tag;
}
void NativeEntryData::set_argc_tag(intptr_t value) const {
FromTypedArray(data_.raw())->argc_tag = value;
}
intptr_t NativeEntryData::GetArgcTag(RawTypedData* data) {
return FromTypedArray(data)->argc_tag;
}
RawTypedData* NativeEntryData::New(MethodRecognizer::Kind kind,
NativeFunctionWrapper trampoline,
NativeFunction native_function,
intptr_t argc_tag) {
const TypedData& data = TypedData::Handle(
TypedData::New(kTypedDataUint8ArrayCid, sizeof(Payload), Heap::kOld));
NativeEntryData native_entry(data);
native_entry.set_kind(kind);
native_entry.set_trampoline(trampoline);
native_entry.set_native_function(native_function);
native_entry.set_argc_tag(argc_tag);
return data.raw();
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
} // namespace dart
+43
View File
@@ -154,6 +154,49 @@ class NativeEntry : public AllStatic {
static void PropagateErrors(NativeArguments* arguments);
};
#if !defined(DART_PRECOMPILED_RUNTIME)
class NativeEntryData : public ValueObject {
public:
explicit NativeEntryData(const TypedData& data) : data_(data) {}
MethodRecognizer::Kind kind() const;
void set_kind(MethodRecognizer::Kind value) const;
static MethodRecognizer::Kind GetKind(RawTypedData* data);
NativeFunctionWrapper trampoline() const;
void set_trampoline(NativeFunctionWrapper value) const;
static NativeFunctionWrapper GetTrampoline(RawTypedData* data);
NativeFunction native_function() const;
void set_native_function(NativeFunction value) const;
static NativeFunction GetNativeFunction(RawTypedData* data);
intptr_t argc_tag() const;
void set_argc_tag(intptr_t value) const;
static intptr_t GetArgcTag(RawTypedData* data);
static RawTypedData* New(MethodRecognizer::Kind kind,
NativeFunctionWrapper trampoline,
NativeFunction native_function,
intptr_t argc_tag);
private:
struct Payload {
NativeFunctionWrapper trampoline;
NativeFunction native_function;
intptr_t argc_tag;
MethodRecognizer::Kind kind;
};
static Payload* FromTypedArray(RawTypedData* data);
const TypedData& data_;
DISALLOW_COPY_AND_ASSIGN(NativeEntryData);
};
#endif // !defined(DART_PRECOMPILED_RUNTIME)
} // namespace dart
#endif // RUNTIME_VM_NATIVE_ENTRY_H_
-40
View File
@@ -120,8 +120,6 @@ RawClass* Object::closure_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
RawClass* Object::signature_data_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
RawClass* Object::redirection_data_class_ =
reinterpret_cast<RawClass*>(RAW_NULL);
RawClass* Object::native_entry_data_class_ =
reinterpret_cast<RawClass*>(RAW_NULL);
RawClass* Object::field_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
RawClass* Object::literal_token_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
RawClass* Object::token_stream_class_ = reinterpret_cast<RawClass*>(RAW_NULL);
@@ -584,9 +582,6 @@ void Object::InitOnce(Isolate* isolate) {
cls = Class::New<RedirectionData>();
redirection_data_class_ = cls.raw();
cls = Class::New<NativeEntryData>();
native_entry_data_class_ = cls.raw();
cls = Class::New<Field>();
field_class_ = cls.raw();
@@ -1027,7 +1022,6 @@ void Object::FinalizeVMIsolate(Isolate* isolate) {
SET_CLASS_NAME(closure_data, ClosureData);
SET_CLASS_NAME(signature_data, SignatureData);
SET_CLASS_NAME(redirection_data, RedirectionData);
SET_CLASS_NAME(native_entry_data, NativeEntryData);
SET_CLASS_NAME(field, Field);
SET_CLASS_NAME(literal_token, LiteralToken);
SET_CLASS_NAME(token_stream, TokenStream);
@@ -3919,8 +3913,6 @@ RawString* Class::GenerateUserVisibleName() const {
return Symbols::SignatureData().raw();
case kRedirectionDataCid:
return Symbols::RedirectionData().raw();
case kNativeEntryDataCid:
return Symbols::NativeEntryData().raw();
case kFieldCid:
return Symbols::Field().raw();
case kLiteralTokenCid:
@@ -8506,38 +8498,6 @@ const char* RedirectionData::ToCString() const {
target_fun.IsNull() ? "null" : target_fun.ToCString());
}
RawNativeEntryData* NativeEntryData::New() {
ASSERT(Object::native_entry_data_class() != Class::null());
RawObject* raw = Object::Allocate(
NativeEntryData::kClassId, NativeEntryData::InstanceSize(), Heap::kOld);
return reinterpret_cast<RawNativeEntryData*>(raw);
}
const char* NativeEntryData::ToCString() const {
#if !defined(DART_PRECOMPILED_RUNTIME)
ASSERT(FLAG_enable_interpreter);
if (IsNull()) {
return "NativeEntryData: null";
}
if (kind() != MethodRecognizer::kUnknown) {
return OS::SCreate(Thread::Current()->zone(), "NativeEntryData %s",
MethodRecognizer::KindToCString(kind()));
}
return OS::SCreate(
Thread::Current()->zone(),
"NativeEntryData argc: %d, trampoline: %s, function: 0x%" Px,
NativeArguments::ArgcBits::decode(argc_tag()),
trampoline() == &NativeEntry::BootstrapNativeCallWrapper
? "BootstrapNativeCallWrapper"
: trampoline() == &NativeEntry::AutoScopeNativeCallWrapper
? "AutoScopeNativeCallWrapper"
: "NoScopeNativeCallWrapper",
reinterpret_cast<uword>(native_function()));
#else
UNREACHABLE();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}
RawField* Field::CloneFromOriginal() const {
return this->Clone(*this);
}
-37
View File
@@ -420,9 +420,6 @@ class Object {
static RawClass* closure_data_class() { return closure_data_class_; }
static RawClass* signature_data_class() { return signature_data_class_; }
static RawClass* redirection_data_class() { return redirection_data_class_; }
static RawClass* native_entry_data_class() {
return native_entry_data_class_;
}
static RawClass* field_class() { return field_class_; }
static RawClass* literal_token_class() { return literal_token_class_; }
static RawClass* token_stream_class() { return token_stream_class_; }
@@ -688,7 +685,6 @@ class Object {
static RawClass* closure_data_class_; // Class of ClosureData vm obj.
static RawClass* signature_data_class_; // Class of SignatureData vm obj.
static RawClass* redirection_data_class_; // Class of RedirectionData vm obj.
static RawClass* native_entry_data_class_; // Class of NativeEntryData.
static RawClass* field_class_; // Class of the Field vm object.
static RawClass* literal_token_class_; // Class of LiteralToken vm object.
static RawClass* token_stream_class_; // Class of the TokenStream vm object.
@@ -3216,39 +3212,6 @@ class RedirectionData : public Object {
friend class HeapProfiler;
};
class NativeEntryData : public Object {
public:
static intptr_t InstanceSize() {
return RoundedAllocationSize(sizeof(RawNativeEntryData));
}
MethodRecognizer::Kind kind() const { return raw_ptr()->kind_; }
void set_kind(MethodRecognizer::Kind value) const {
StoreNonPointer(&raw_ptr()->kind_, value);
}
NativeFunctionWrapper trampoline() const { return raw_ptr()->trampoline_; }
void set_trampoline(NativeFunctionWrapper value) const {
StoreNonPointer(&raw_ptr()->trampoline_, value);
}
NativeFunction native_function() const { return raw_ptr()->native_function_; }
void set_native_function(NativeFunction value) const {
StoreNonPointer(&raw_ptr()->native_function_, value);
}
intptr_t argc_tag() const { return raw_ptr()->argc_tag_; }
void set_argc_tag(intptr_t value) const {
StoreNonPointer(&raw_ptr()->argc_tag_, value);
}
static RawNativeEntryData* New();
FINAL_HEAP_OBJECT_IMPLEMENTATION(NativeEntryData, Object);
friend class Class;
friend class HeapProfiler;
};
class Field : public Object {
public:
RawField* Original() const;
-4
View File
@@ -346,10 +346,6 @@ void RedirectionData::PrintJSONImpl(JSONStream* stream, bool ref) const {
Object::PrintJSONImpl(stream, ref);
}
void NativeEntryData::PrintJSONImpl(JSONStream* stream, bool ref) const {
Object::PrintJSONImpl(stream, ref);
}
void Field::PrintJSONImpl(JSONStream* stream, bool ref) const {
JSONObject jsobj(stream);
Class& cls = Class::Handle(Owner());
-1
View File
@@ -380,7 +380,6 @@ COMPRESSED_VISITOR(Closure)
REGULAR_VISITOR(ClosureData)
REGULAR_VISITOR(SignatureData)
REGULAR_VISITOR(RedirectionData)
NULL_VISITOR(NativeEntryData)
REGULAR_VISITOR(Field)
REGULAR_VISITOR(LiteralToken)
REGULAR_VISITOR(TokenStream)
+5 -22
View File
@@ -28,7 +28,6 @@ typedef RawObject* RawCompressed;
V(ClosureData) \
V(SignatureData) \
V(RedirectionData) \
V(NativeEntryData) \
V(Field) \
V(LiteralToken) \
V(TokenStream) \
@@ -1107,23 +1106,6 @@ class RawRedirectionData : public RawObject {
VISIT_TO(RawObject*, target_);
};
// Forward declarations.
class NativeArguments;
typedef void (*NativeFunction)(NativeArguments* arguments);
typedef void (*NativeFunctionWrapper)(Dart_NativeArguments args,
Dart_NativeFunction func);
class RawNativeEntryData : public RawObject {
private:
RAW_HEAP_OBJECT_IMPLEMENTATION(NativeEntryData);
VISIT_NOTHING();
NativeFunctionWrapper trampoline_;
NativeFunction native_function_;
intptr_t argc_tag_;
MethodRecognizer::Kind kind_;
};
class RawField : public RawObject {
RAW_HEAP_OBJECT_IMPLEMENTATION(Field);
@@ -2336,13 +2318,14 @@ class RawTypedData : public RawInstance {
const uint8_t* data() const { OPEN_ARRAY_START(uint8_t, uint8_t); }
friend class Api;
friend class Object;
friend class Instance;
friend class SnapshotReader;
friend class NativeEntryData;
friend class Object;
friend class ObjectPool;
friend class RawObjectPool;
friend class ObjectPoolSerializationCluster;
friend class ObjectPoolDeserializationCluster;
friend class ObjectPoolSerializationCluster;
friend class RawObjectPool;
friend class SnapshotReader;
};
class RawExternalTypedData : public RawInstance {
-16
View File
@@ -746,22 +746,6 @@ void RawRedirectionData::WriteTo(SnapshotWriter* writer,
visitor.VisitPointers(from(), to());
}
RawNativeEntryData* NativeEntryData::ReadFrom(SnapshotReader* reader,
intptr_t object_id,
intptr_t tags,
Snapshot::Kind kind,
bool as_reference) {
UNREACHABLE();
return NativeEntryData::null();
}
void RawNativeEntryData::WriteTo(SnapshotWriter* writer,
intptr_t object_id,
Snapshot::Kind kind,
bool as_reference) {
UNREACHABLE();
}
RawFunction* Function::ReadFrom(SnapshotReader* reader,
intptr_t object_id,
intptr_t tags,
-1
View File
@@ -183,7 +183,6 @@ class ObjectPointerVisitor;
V(ClosureData, "ClosureData") \
V(SignatureData, "SignatureData") \
V(RedirectionData, "RedirectionData") \
V(NativeEntryData, "NativeEntryData") \
V(Field, "Field") \
V(LiteralToken, "LiteralToken") \
V(TokenStream, "TokenStream") \