Commit 2702d0fb authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] [codestyle] Fix pointer alignment in wasm-debug.cc

Our .clang-format is derived on the Google style, which sets
PointerAlignment to left (e.g. "Type* name"), but sets
DerivePointerAlignment to true. Once we started with the wrong style,
this made all new code in wasm-debug.cc use PointerAlignment=right,
resulting in lots of code using the wrong style.

For this CL, I ran
clang-format -style="{DerivePointerAlignment: false, BasedOnStyle: \
  Google}" -i src/wasm/wasm-debug.cc

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2635003002
Cr-Commit-Position: refs/heads/master@{#42380}
parent 4f556e9e
...@@ -29,7 +29,7 @@ class InterpreterHandle { ...@@ -29,7 +29,7 @@ class InterpreterHandle {
public: public:
// Initialize in the right order, using helper methods to make this possible. // Initialize in the right order, using helper methods to make this possible.
// WasmInterpreter has to be allocated in place, since it is not movable. // WasmInterpreter has to be allocated in place, since it is not movable.
InterpreterHandle(Isolate *isolate, WasmDebugInfo *debug_info) InterpreterHandle(Isolate* isolate, WasmDebugInfo* debug_info)
: instance_(debug_info->wasm_instance()->compiled_module()->module()), : instance_(debug_info->wasm_instance()->compiled_module()->module()),
interpreter_(GetBytesEnv(&instance_, debug_info), &allocator_) { interpreter_(GetBytesEnv(&instance_, debug_info), &allocator_) {
Handle<JSArrayBuffer> mem_buffer = Handle<JSArrayBuffer> mem_buffer =
...@@ -40,37 +40,37 @@ class InterpreterHandle { ...@@ -40,37 +40,37 @@ class InterpreterHandle {
instance_.mem_size = 0; instance_.mem_size = 0;
} else { } else {
instance_.mem_start = instance_.mem_start =
reinterpret_cast<byte *>(mem_buffer->backing_store()); reinterpret_cast<byte*>(mem_buffer->backing_store());
CHECK(mem_buffer->byte_length()->ToUint32(&instance_.mem_size)); CHECK(mem_buffer->byte_length()->ToUint32(&instance_.mem_size));
} }
} }
static ModuleBytesEnv GetBytesEnv(WasmInstance *instance, static ModuleBytesEnv GetBytesEnv(WasmInstance* instance,
WasmDebugInfo *debug_info) { WasmDebugInfo* debug_info) {
// Return raw pointer into heap. The WasmInterpreter will make its own copy // Return raw pointer into heap. The WasmInterpreter will make its own copy
// of this data anyway, and there is no heap allocation in-between. // of this data anyway, and there is no heap allocation in-between.
SeqOneByteString *bytes_str = SeqOneByteString* bytes_str =
debug_info->wasm_instance()->compiled_module()->module_bytes(); debug_info->wasm_instance()->compiled_module()->module_bytes();
Vector<const byte> bytes(bytes_str->GetChars(), bytes_str->length()); Vector<const byte> bytes(bytes_str->GetChars(), bytes_str->length());
return ModuleBytesEnv(instance->module, instance, bytes); return ModuleBytesEnv(instance->module, instance, bytes);
} }
WasmInterpreter *interpreter() { return &interpreter_; } WasmInterpreter* interpreter() { return &interpreter_; }
const WasmModule *module() { return instance_.module; } const WasmModule* module() { return instance_.module; }
void Execute(uint32_t func_index, uint8_t *arg_buffer) { void Execute(uint32_t func_index, uint8_t* arg_buffer) {
DCHECK_GE(module()->functions.size(), func_index); DCHECK_GE(module()->functions.size(), func_index);
FunctionSig *sig = module()->functions[func_index].sig; FunctionSig* sig = module()->functions[func_index].sig;
DCHECK_GE(kMaxInt, sig->parameter_count()); DCHECK_GE(kMaxInt, sig->parameter_count());
int num_params = static_cast<int>(sig->parameter_count()); int num_params = static_cast<int>(sig->parameter_count());
ScopedVector<WasmVal> wasm_args(num_params); ScopedVector<WasmVal> wasm_args(num_params);
uint8_t *arg_buf_ptr = arg_buffer; uint8_t* arg_buf_ptr = arg_buffer;
for (int i = 0; i < num_params; ++i) { for (int i = 0; i < num_params; ++i) {
uint32_t param_size = 1 << ElementSizeLog2Of(sig->GetParam(i)); uint32_t param_size = 1 << ElementSizeLog2Of(sig->GetParam(i));
#define CASE_ARG_TYPE(type, ctype) \ #define CASE_ARG_TYPE(type, ctype) \
case type: \ case type: \
DCHECK_EQ(param_size, sizeof(ctype)); \ DCHECK_EQ(param_size, sizeof(ctype)); \
wasm_args[i] = WasmVal(*reinterpret_cast<ctype *>(arg_buf_ptr)); \ wasm_args[i] = WasmVal(*reinterpret_cast<ctype*>(arg_buf_ptr)); \
break; break;
switch (sig->GetParam(i)) { switch (sig->GetParam(i)) {
CASE_ARG_TYPE(kWasmI32, uint32_t) CASE_ARG_TYPE(kWasmI32, uint32_t)
...@@ -84,7 +84,7 @@ class InterpreterHandle { ...@@ -84,7 +84,7 @@ class InterpreterHandle {
arg_buf_ptr += param_size; arg_buf_ptr += param_size;
} }
WasmInterpreter::Thread *thread = interpreter_.GetThread(0); WasmInterpreter::Thread* thread = interpreter_.GetThread(0);
// We do not support reentering an already running interpreter at the moment // We do not support reentering an already running interpreter at the moment
// (like INTERPRETER -> JS -> WASM -> INTERPRETER). // (like INTERPRETER -> JS -> WASM -> INTERPRETER).
DCHECK(thread->state() == WasmInterpreter::STOPPED || DCHECK(thread->state() == WasmInterpreter::STOPPED ||
...@@ -123,7 +123,7 @@ class InterpreterHandle { ...@@ -123,7 +123,7 @@ class InterpreterHandle {
#define CASE_RET_TYPE(type, ctype) \ #define CASE_RET_TYPE(type, ctype) \
case type: \ case type: \
DCHECK_EQ(1 << ElementSizeLog2Of(sig->GetReturn(0)), sizeof(ctype)); \ DCHECK_EQ(1 << ElementSizeLog2Of(sig->GetReturn(0)), sizeof(ctype)); \
*reinterpret_cast<ctype *>(arg_buffer) = ret_val.to<ctype>(); \ *reinterpret_cast<ctype*>(arg_buffer) = ret_val.to<ctype>(); \
break; break;
switch (sig->GetReturn(0)) { switch (sig->GetReturn(0)) {
CASE_RET_TYPE(kWasmI32, uint32_t) CASE_RET_TYPE(kWasmI32, uint32_t)
...@@ -138,12 +138,12 @@ class InterpreterHandle { ...@@ -138,12 +138,12 @@ class InterpreterHandle {
} }
}; };
InterpreterHandle *GetOrCreateInterpreterHandle( InterpreterHandle* GetOrCreateInterpreterHandle(
Isolate *isolate, Handle<WasmDebugInfo> debug_info) { Isolate* isolate, Handle<WasmDebugInfo> debug_info) {
Handle<Object> handle(debug_info->get(WasmDebugInfo::kInterpreterHandle), Handle<Object> handle(debug_info->get(WasmDebugInfo::kInterpreterHandle),
isolate); isolate);
if (handle->IsUndefined(isolate)) { if (handle->IsUndefined(isolate)) {
InterpreterHandle *cpp_handle = new InterpreterHandle(isolate, *debug_info); InterpreterHandle* cpp_handle = new InterpreterHandle(isolate, *debug_info);
handle = Managed<InterpreterHandle>::New(isolate, cpp_handle); handle = Managed<InterpreterHandle>::New(isolate, cpp_handle);
debug_info->set(WasmDebugInfo::kInterpreterHandle, *handle); debug_info->set(WasmDebugInfo::kInterpreterHandle, *handle);
} }
...@@ -151,7 +151,7 @@ InterpreterHandle *GetOrCreateInterpreterHandle( ...@@ -151,7 +151,7 @@ InterpreterHandle *GetOrCreateInterpreterHandle(
return Handle<Managed<InterpreterHandle>>::cast(handle)->get(); return Handle<Managed<InterpreterHandle>>::cast(handle)->get();
} }
int GetNumFunctions(WasmInstanceObject *instance) { int GetNumFunctions(WasmInstanceObject* instance) {
size_t num_functions = size_t num_functions =
instance->compiled_module()->module()->functions.size(); instance->compiled_module()->module()->functions.size();
DCHECK_GE(kMaxInt, num_functions); DCHECK_GE(kMaxInt, num_functions);
...@@ -159,7 +159,7 @@ int GetNumFunctions(WasmInstanceObject *instance) { ...@@ -159,7 +159,7 @@ int GetNumFunctions(WasmInstanceObject *instance) {
} }
Handle<FixedArray> GetOrCreateInterpretedFunctions( Handle<FixedArray> GetOrCreateInterpretedFunctions(
Isolate *isolate, Handle<WasmDebugInfo> debug_info) { Isolate* isolate, Handle<WasmDebugInfo> debug_info) {
Handle<Object> obj(debug_info->get(WasmDebugInfo::kInterpretedFunctions), Handle<Object> obj(debug_info->get(WasmDebugInfo::kInterpretedFunctions),
isolate); isolate);
if (!obj->IsUndefined(isolate)) return Handle<FixedArray>::cast(obj); if (!obj->IsUndefined(isolate)) return Handle<FixedArray>::cast(obj);
...@@ -170,39 +170,39 @@ Handle<FixedArray> GetOrCreateInterpretedFunctions( ...@@ -170,39 +170,39 @@ Handle<FixedArray> GetOrCreateInterpretedFunctions(
return new_arr; return new_arr;
} }
void RedirectCallsitesInCode(Code *code, Code *old_target, Code *new_target) { void RedirectCallsitesInCode(Code* code, Code* old_target, Code* new_target) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
for (RelocIterator it(code, RelocInfo::kCodeTargetMask); !it.done(); for (RelocIterator it(code, RelocInfo::kCodeTargetMask); !it.done();
it.next()) { it.next()) {
DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode())); DCHECK(RelocInfo::IsCodeTarget(it.rinfo()->rmode()));
Code *target = Code::GetCodeFromTargetAddress(it.rinfo()->target_address()); Code* target = Code::GetCodeFromTargetAddress(it.rinfo()->target_address());
if (target != old_target) continue; if (target != old_target) continue;
it.rinfo()->set_target_address(new_target->instruction_start()); it.rinfo()->set_target_address(new_target->instruction_start());
} }
} }
void RedirectCallsitesInInstance(Isolate *isolate, WasmInstanceObject *instance, void RedirectCallsitesInInstance(Isolate* isolate, WasmInstanceObject* instance,
Code *old_target, Code *new_target) { Code* old_target, Code* new_target) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
// Redirect all calls in wasm functions. // Redirect all calls in wasm functions.
FixedArray *code_table = instance->compiled_module()->ptr_to_code_table(); FixedArray* code_table = instance->compiled_module()->ptr_to_code_table();
for (int i = 0, e = GetNumFunctions(instance); i < e; ++i) { for (int i = 0, e = GetNumFunctions(instance); i < e; ++i) {
RedirectCallsitesInCode(Code::cast(code_table->get(i)), old_target, RedirectCallsitesInCode(Code::cast(code_table->get(i)), old_target,
new_target); new_target);
} }
// Redirect all calls in exported functions. // Redirect all calls in exported functions.
FixedArray *weak_exported_functions = FixedArray* weak_exported_functions =
instance->compiled_module()->ptr_to_weak_exported_functions(); instance->compiled_module()->ptr_to_weak_exported_functions();
for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) { for (int i = 0, e = weak_exported_functions->length(); i != e; ++i) {
WeakCell *weak_function = WeakCell::cast(weak_exported_functions->get(i)); WeakCell* weak_function = WeakCell::cast(weak_exported_functions->get(i));
if (weak_function->cleared()) continue; if (weak_function->cleared()) continue;
Code *code = JSFunction::cast(weak_function->value())->code(); Code* code = JSFunction::cast(weak_function->value())->code();
RedirectCallsitesInCode(code, old_target, new_target); RedirectCallsitesInCode(code, old_target, new_target);
} }
} }
void EnsureRedirectToInterpreter(Isolate *isolate, void EnsureRedirectToInterpreter(Isolate* isolate,
Handle<WasmDebugInfo> debug_info, Handle<WasmDebugInfo> debug_info,
int func_index) { int func_index) {
Handle<FixedArray> interpreted_functions = Handle<FixedArray> interpreted_functions =
...@@ -225,50 +225,50 @@ void EnsureRedirectToInterpreter(Isolate *isolate, ...@@ -225,50 +225,50 @@ void EnsureRedirectToInterpreter(Isolate *isolate,
} // namespace } // namespace
Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) { Handle<WasmDebugInfo> WasmDebugInfo::New(Handle<WasmInstanceObject> instance) {
Isolate *isolate = instance->GetIsolate(); Isolate* isolate = instance->GetIsolate();
Factory *factory = isolate->factory(); Factory* factory = isolate->factory();
Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED); Handle<FixedArray> arr = factory->NewFixedArray(kFieldCount, TENURED);
arr->set(kInstance, *instance); arr->set(kInstance, *instance);
return Handle<WasmDebugInfo>::cast(arr); return Handle<WasmDebugInfo>::cast(arr);
} }
bool WasmDebugInfo::IsDebugInfo(Object *object) { bool WasmDebugInfo::IsDebugInfo(Object* object) {
if (!object->IsFixedArray()) return false; if (!object->IsFixedArray()) return false;
FixedArray *arr = FixedArray::cast(object); FixedArray* arr = FixedArray::cast(object);
if (arr->length() != kFieldCount) return false; if (arr->length() != kFieldCount) return false;
if (!IsWasmInstance(arr->get(kInstance))) return false; if (!IsWasmInstance(arr->get(kInstance))) return false;
Isolate *isolate = arr->GetIsolate(); Isolate* isolate = arr->GetIsolate();
if (!arr->get(kInterpreterHandle)->IsUndefined(isolate) && if (!arr->get(kInterpreterHandle)->IsUndefined(isolate) &&
!arr->get(kInterpreterHandle)->IsForeign()) !arr->get(kInterpreterHandle)->IsForeign())
return false; return false;
return true; return true;
} }
WasmDebugInfo *WasmDebugInfo::cast(Object *object) { WasmDebugInfo* WasmDebugInfo::cast(Object* object) {
DCHECK(IsDebugInfo(object)); DCHECK(IsDebugInfo(object));
return reinterpret_cast<WasmDebugInfo *>(object); return reinterpret_cast<WasmDebugInfo*>(object);
} }
WasmInstanceObject *WasmDebugInfo::wasm_instance() { WasmInstanceObject* WasmDebugInfo::wasm_instance() {
return WasmInstanceObject::cast(get(kInstance)); return WasmInstanceObject::cast(get(kInstance));
} }
void WasmDebugInfo::SetBreakpoint(Handle<WasmDebugInfo> debug_info, void WasmDebugInfo::SetBreakpoint(Handle<WasmDebugInfo> debug_info,
int func_index, int offset) { int func_index, int offset) {
Isolate *isolate = debug_info->GetIsolate(); Isolate* isolate = debug_info->GetIsolate();
InterpreterHandle *handle = GetOrCreateInterpreterHandle(isolate, debug_info); InterpreterHandle* handle = GetOrCreateInterpreterHandle(isolate, debug_info);
WasmInterpreter *interpreter = handle->interpreter(); WasmInterpreter* interpreter = handle->interpreter();
DCHECK_LE(0, func_index); DCHECK_LE(0, func_index);
DCHECK_GT(handle->module()->functions.size(), func_index); DCHECK_GT(handle->module()->functions.size(), func_index);
const WasmFunction *func = &handle->module()->functions[func_index]; const WasmFunction* func = &handle->module()->functions[func_index];
interpreter->SetBreakpoint(func, offset, true); interpreter->SetBreakpoint(func, offset, true);
EnsureRedirectToInterpreter(isolate, debug_info, func_index); EnsureRedirectToInterpreter(isolate, debug_info, func_index);
} }
void WasmDebugInfo::RunInterpreter(Handle<WasmDebugInfo> debug_info, void WasmDebugInfo::RunInterpreter(Handle<WasmDebugInfo> debug_info,
int func_index, uint8_t *arg_buffer) { int func_index, uint8_t* arg_buffer) {
DCHECK_LE(0, func_index); DCHECK_LE(0, func_index);
InterpreterHandle *interp_handle = InterpreterHandle* interp_handle =
GetOrCreateInterpreterHandle(debug_info->GetIsolate(), debug_info); GetOrCreateInterpreterHandle(debug_info->GetIsolate(), debug_info);
interp_handle->Execute(static_cast<uint32_t>(func_index), arg_buffer); interp_handle->Execute(static_cast<uint32_t>(func_index), arg_buffer);
} }
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