a17b52c2c1
This reverts commit fde6a5917e.
Reason for revert: This commit looks to be causing new test failures on dart2js. While there are some odd results on some builders that look like infra failures, some builders (for example, dart2js-minified-strong-linux-x64-d8) show the new failing tests clearly.
Original change's description:
> [vm, compiler] Unoptimized megamorphic calls.
>
> When an instance call in unoptimized code creates more than FLAG_max_polymorphic_checks cases, switch the call to use a MegamorphicCache instead of ICData. The prevents unbounded collection of type feedback, and gives improvements on microbenchmarks in the 3-8% range for unoptimized code.
>
> It also leads to a loss of target frequency information for the optimizer, leading to different ordering for range checks in polymorphic inlining. This leads to changes on megamorphic microbenchmarks from -31% to +60%, weighted toward the negative end.
>
> In practice the frequency information seems unimportant, as dart2js has 4.01% geomean improvement.
>
> This is a step toward direct monomorphic calls in unoptimized code, which will also make use of the patching and type feedback extraction added here.
>
> Bug: https://github.com/dart-lang/sdk/issues/26780
> Bug: https://github.com/dart-lang/sdk/issues/36409
> Bug: https://github.com/dart-lang/sdk/issues/36731
> Change-Id: I29f53f23b6794c5f5f0db8b8184788cee16fd9c5
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99270
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
TBR=rmacnak@google.com,alexmarkov@google.com,ajcbik@google.com
Change-Id: Icad46b93cdf8541a00563f49da6b4ac0a4df1ba1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/26780, https://github.com/dart-lang/sdk/issues/36409, https://github.com/dart-lang/sdk/issues/36731
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103440
Reviewed-by: Teagan Strickland <sstrickl@google.com>
Commit-Queue: Teagan Strickland <sstrickl@google.com>
126 lines
4.8 KiB
C++
126 lines
4.8 KiB
C++
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
|
// 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.
|
|
// Class for patching compiled code.
|
|
|
|
#ifndef RUNTIME_VM_CODE_PATCHER_H_
|
|
#define RUNTIME_VM_CODE_PATCHER_H_
|
|
|
|
#include "vm/allocation.h"
|
|
#include "vm/native_entry.h"
|
|
|
|
namespace dart {
|
|
|
|
// Forward declaration.
|
|
class Code;
|
|
class ICData;
|
|
class RawArray;
|
|
class RawCode;
|
|
class RawFunction;
|
|
class RawObject;
|
|
|
|
#if defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_DBC)
|
|
// Stack-allocated class to create a scope where the specified region
|
|
// [address, address + size] has write access enabled. This is used
|
|
// when patching generated code. Access is reset to read-execute in
|
|
// the destructor of this scope.
|
|
// Dual mapping of instructions pages is not supported on these target arch.
|
|
class WritableInstructionsScope : public ValueObject {
|
|
public:
|
|
WritableInstructionsScope(uword address, intptr_t size);
|
|
~WritableInstructionsScope();
|
|
|
|
private:
|
|
const uword address_;
|
|
const intptr_t size_;
|
|
};
|
|
#endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_DBC)
|
|
|
|
class CodePatcher : public AllStatic {
|
|
public:
|
|
// Dart static calls have a distinct, machine-dependent code pattern.
|
|
|
|
// Patch static call before return_address in given code to the new target.
|
|
static void PatchStaticCallAt(uword return_address,
|
|
const Code& code,
|
|
const Code& new_target);
|
|
|
|
// Return the target address of the static call before return_address
|
|
// in given code.
|
|
static RawCode* GetStaticCallTargetAt(uword return_address, const Code& code);
|
|
|
|
// Get instance call information. Returns the call target and sets each
|
|
// of the output parameters ic_data and arguments_descriptor if they are
|
|
// non-NULL.
|
|
static RawCode* GetInstanceCallAt(uword return_address,
|
|
const Code& code,
|
|
ICData* ic_data);
|
|
|
|
// Return target of an unoptimized static call and its ICData object
|
|
// (calls target via a stub).
|
|
static RawFunction* GetUnoptimizedStaticCallAt(uword return_address,
|
|
const Code& code,
|
|
ICData* ic_data);
|
|
|
|
static void InsertDeoptimizationCallAt(uword start);
|
|
|
|
static void PatchPoolPointerCallAt(uword return_address,
|
|
const Code& code,
|
|
const Code& new_target);
|
|
|
|
static void PatchSwitchableCallAt(uword return_address,
|
|
const Code& caller_code,
|
|
const Object& data,
|
|
const Code& target);
|
|
static RawObject* GetSwitchableCallDataAt(uword return_address,
|
|
const Code& caller_code);
|
|
static RawCode* GetSwitchableCallTargetAt(uword return_address,
|
|
const Code& caller_code);
|
|
|
|
#if defined(TARGET_ARCH_DBC)
|
|
static NativeFunctionWrapper GetNativeCallAt(uword return_address,
|
|
const Code& code,
|
|
NativeFunction* target);
|
|
#else
|
|
static RawCode* GetNativeCallAt(uword return_address,
|
|
const Code& code,
|
|
NativeFunction* target);
|
|
#endif
|
|
|
|
#if defined(TARGET_ARCH_DBC)
|
|
static void PatchNativeCallAt(uword return_address,
|
|
const Code& code,
|
|
NativeFunction target,
|
|
NativeFunctionWrapper trampoline);
|
|
#else
|
|
static void PatchNativeCallAt(uword return_address,
|
|
const Code& code,
|
|
NativeFunction target,
|
|
const Code& trampoline);
|
|
#endif
|
|
|
|
static intptr_t GetSubtypeTestCachePoolIndex(uword return_address);
|
|
};
|
|
|
|
// Beginning from [end - size] we compare [size] bytes with [pattern]. All
|
|
// [0..255] values in [pattern] have to match, negative values are skipped.
|
|
//
|
|
// Example pattern: `[0x3d, 0x8b, -1, -1]`.
|
|
bool MatchesPattern(uword end, const int16_t* pattern, intptr_t size);
|
|
|
|
class KBCPatcher : public AllStatic {
|
|
public:
|
|
static NativeFunctionWrapper GetNativeCallAt(uword return_address,
|
|
const Bytecode& bytecode,
|
|
NativeFunction* function);
|
|
|
|
static void PatchNativeCallAt(uword return_address,
|
|
const Bytecode& bytecode,
|
|
NativeFunction function,
|
|
NativeFunctionWrapper trampoline);
|
|
};
|
|
|
|
} // namespace dart
|
|
|
|
#endif // RUNTIME_VM_CODE_PATCHER_H_
|