2008-07-03 15:10:15 +00:00
|
|
|
// Copyright (c) 1994-2006 Sun Microsystems Inc.
|
|
|
|
// All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// - Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
//
|
|
|
|
// - Redistribution in binary form must reproduce the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer in the
|
|
|
|
// documentation and/or other materials provided with the distribution.
|
|
|
|
//
|
|
|
|
// - Neither the name of Sun Microsystems or the names of contributors may
|
|
|
|
// be used to endorse or promote products derived from this software without
|
|
|
|
// specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
|
|
|
// IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
|
|
|
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
|
|
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
|
|
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
|
|
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
// The original source code covered by the above license above has been
|
|
|
|
// modified significantly by Google Inc.
|
2012-01-25 16:31:25 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
#ifndef V8_ASSEMBLER_H_
|
|
|
|
#define V8_ASSEMBLER_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
|
|
|
#include "src/builtins.h"
|
|
|
|
#include "src/isolate.h"
|
2016-03-02 02:10:03 +00:00
|
|
|
#include "src/log.h"
|
2014-09-25 07:16:15 +00:00
|
|
|
#include "src/runtime/runtime.h"
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace v8 {
|
2012-01-25 16:31:25 +00:00
|
|
|
|
2015-08-12 07:32:36 +00:00
|
|
|
// Forward declarations.
|
2012-01-25 16:31:25 +00:00
|
|
|
class ApiFunction;
|
|
|
|
|
2009-05-25 10:05:56 +00:00
|
|
|
namespace internal {
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-08-12 07:32:36 +00:00
|
|
|
// Forward declarations.
|
2013-04-24 14:05:37 +00:00
|
|
|
class StatsCounter;
|
2015-08-12 07:32:36 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Platform independent assembler base class.
|
|
|
|
|
2015-11-25 14:23:37 +00:00
|
|
|
enum class CodeObjectRequired { kNo, kYes };
|
|
|
|
|
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
class AssemblerBase: public Malloced {
|
|
|
|
public:
|
2012-11-22 10:28:29 +00:00
|
|
|
AssemblerBase(Isolate* isolate, void* buffer, int buffer_size);
|
|
|
|
virtual ~AssemblerBase();
|
2011-03-22 13:20:04 +00:00
|
|
|
|
|
|
|
Isolate* isolate() const { return isolate_; }
|
2012-11-09 13:10:10 +00:00
|
|
|
int jit_cookie() const { return jit_cookie_; }
|
|
|
|
|
2012-11-09 13:43:48 +00:00
|
|
|
bool emit_debug_code() const { return emit_debug_code_; }
|
|
|
|
void set_emit_debug_code(bool value) { emit_debug_code_ = value; }
|
|
|
|
|
2014-05-16 15:18:24 +00:00
|
|
|
bool serializer_enabled() const { return serializer_enabled_; }
|
2014-07-08 09:04:08 +00:00
|
|
|
void enable_serializer() { serializer_enabled_ = true; }
|
2014-05-16 15:18:24 +00:00
|
|
|
|
2012-11-09 13:10:10 +00:00
|
|
|
bool predictable_code_size() const { return predictable_code_size_; }
|
|
|
|
void set_predictable_code_size(bool value) { predictable_code_size_ = value; }
|
2011-03-22 13:20:04 +00:00
|
|
|
|
2013-03-05 10:48:16 +00:00
|
|
|
uint64_t enabled_cpu_features() const { return enabled_cpu_features_; }
|
|
|
|
void set_enabled_cpu_features(uint64_t features) {
|
|
|
|
enabled_cpu_features_ = features;
|
|
|
|
}
|
|
|
|
bool IsEnabled(CpuFeature f) {
|
|
|
|
return (enabled_cpu_features_ & (static_cast<uint64_t>(1) << f)) != 0;
|
|
|
|
}
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
bool is_constant_pool_available() const {
|
|
|
|
if (FLAG_enable_embedded_constant_pool) {
|
|
|
|
return constant_pool_available_;
|
2014-10-13 14:41:33 +00:00
|
|
|
} else {
|
2015-06-04 14:44:00 +00:00
|
|
|
// Embedded constant pool not supported on this architecture.
|
2014-10-13 14:41:33 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-12 09:23:26 +00:00
|
|
|
// Overwrite a host NaN with a quiet target NaN. Used by mksnapshot for
|
|
|
|
// cross-snapshotting.
|
|
|
|
static void QuietNaN(HeapObject* nan) { }
|
|
|
|
|
2012-11-22 10:28:29 +00:00
|
|
|
int pc_offset() const { return static_cast<int>(pc_ - buffer_); }
|
|
|
|
|
2014-03-20 09:10:15 +00:00
|
|
|
// This function is called when code generation is aborted, so that
|
|
|
|
// the assembler could clean up internal data structures.
|
|
|
|
virtual void AbortedCodeGeneration() { }
|
|
|
|
|
[assembler] Introduce proper AssemblerBase::Print() for improved debuggability.
While working on frame elision, I wanted to disassemble codegen in the
debugger, as the code generation is progressing. I discovered we had a
"Print" member on the x64 assembler, without any implementation. I
pulled it up to AssemblerBase and gave it an implementation that
should work for the other architectures.
Also checked that ia32, x87, arm and arm64 assemblers didn't have
such an implementation - free Print.
Arm64 has a naming conflict with the v8::internal::Disassembler. I
renamed the arm64 type with a more specific name.
Opportunistically fixed a bug in the name converter. This debug-time
printer doesn't provide a Code object, which should be OK with the
name converters, by the looks of other APIs there. All this means is that
when using the Print() API, we just get addresses dumped without any
context (like what this address may be - a stub maybe, etc). This seems
fine for the scenario.
There may be other places that assume a Code object. Since this is
a diagnostics-only scenario, for codegen developers, I feel it is
reasonable to fix such other places as we find them.
Review URL: https://codereview.chromium.org/1431933003
Cr-Commit-Position: refs/heads/master@{#31869}
2015-11-09 05:39:20 +00:00
|
|
|
// Debugging
|
|
|
|
void Print();
|
|
|
|
|
2012-11-22 10:28:29 +00:00
|
|
|
static const int kMinimalBufferSize = 4*KB;
|
|
|
|
|
2015-09-11 12:59:30 +00:00
|
|
|
static void FlushICache(Isolate* isolate, void* start, size_t size);
|
|
|
|
|
2012-11-22 10:28:29 +00:00
|
|
|
protected:
|
|
|
|
// The buffer into which code and relocation info are generated. It could
|
|
|
|
// either be owned by the assembler or be provided externally.
|
|
|
|
byte* buffer_;
|
|
|
|
int buffer_size_;
|
|
|
|
bool own_buffer_;
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
void set_constant_pool_available(bool available) {
|
|
|
|
if (FLAG_enable_embedded_constant_pool) {
|
|
|
|
constant_pool_available_ = available;
|
2014-10-13 14:41:33 +00:00
|
|
|
} else {
|
2015-06-04 14:44:00 +00:00
|
|
|
// Embedded constant pool not supported on this architecture.
|
2014-10-13 14:41:33 +00:00
|
|
|
UNREACHABLE();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-22 10:28:29 +00:00
|
|
|
// The program counter, which points into the buffer above and moves forward.
|
|
|
|
byte* pc_;
|
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
private:
|
|
|
|
Isolate* isolate_;
|
2011-05-11 14:16:24 +00:00
|
|
|
int jit_cookie_;
|
2013-03-05 10:48:16 +00:00
|
|
|
uint64_t enabled_cpu_features_;
|
2012-11-09 13:43:48 +00:00
|
|
|
bool emit_debug_code_;
|
2012-11-09 13:10:10 +00:00
|
|
|
bool predictable_code_size_;
|
2014-05-16 15:18:24 +00:00
|
|
|
bool serializer_enabled_;
|
2014-10-13 14:41:33 +00:00
|
|
|
|
|
|
|
// Indicates whether the constant pool can be accessed, which is only possible
|
|
|
|
// if the pp register points to the current code object's constant pool.
|
2015-06-04 14:44:00 +00:00
|
|
|
bool constant_pool_available_;
|
2014-10-13 14:41:33 +00:00
|
|
|
|
|
|
|
// Constant pool.
|
|
|
|
friend class FrameAndConstantPoolScope;
|
|
|
|
friend class ConstantPoolUnavailableScope;
|
2012-11-09 13:10:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-04-16 02:06:14 +00:00
|
|
|
// Avoids emitting debug code during the lifetime of this scope object.
|
|
|
|
class DontEmitDebugCodeScope BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
explicit DontEmitDebugCodeScope(AssemblerBase* assembler)
|
|
|
|
: assembler_(assembler), old_value_(assembler->emit_debug_code()) {
|
|
|
|
assembler_->set_emit_debug_code(false);
|
|
|
|
}
|
|
|
|
~DontEmitDebugCodeScope() {
|
|
|
|
assembler_->set_emit_debug_code(old_value_);
|
2014-05-09 12:59:24 +00:00
|
|
|
}
|
2014-04-16 02:06:14 +00:00
|
|
|
private:
|
|
|
|
AssemblerBase* assembler_;
|
|
|
|
bool old_value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-11-09 13:10:10 +00:00
|
|
|
// Avoids using instructions that vary in size in unpredictable ways between the
|
|
|
|
// snapshot and the running VM.
|
|
|
|
class PredictableCodeSizeScope {
|
|
|
|
public:
|
2015-07-21 11:18:22 +00:00
|
|
|
explicit PredictableCodeSizeScope(AssemblerBase* assembler);
|
2012-11-22 14:59:52 +00:00
|
|
|
PredictableCodeSizeScope(AssemblerBase* assembler, int expected_size);
|
|
|
|
~PredictableCodeSizeScope();
|
2015-07-21 11:18:22 +00:00
|
|
|
void ExpectSize(int expected_size) { expected_size_ = expected_size; }
|
2012-11-09 13:10:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
AssemblerBase* assembler_;
|
2012-11-22 14:59:52 +00:00
|
|
|
int expected_size_;
|
|
|
|
int start_offset_;
|
2012-11-09 13:10:10 +00:00
|
|
|
bool old_value_;
|
2011-03-22 13:20:04 +00:00
|
|
|
};
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-03-05 10:48:16 +00:00
|
|
|
// Enable a specified feature within a scope.
|
|
|
|
class CpuFeatureScope BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
#ifdef DEBUG
|
|
|
|
CpuFeatureScope(AssemblerBase* assembler, CpuFeature f);
|
|
|
|
~CpuFeatureScope();
|
|
|
|
|
|
|
|
private:
|
|
|
|
AssemblerBase* assembler_;
|
|
|
|
uint64_t old_enabled_;
|
|
|
|
#else
|
|
|
|
CpuFeatureScope(AssemblerBase* assembler, CpuFeature f) {}
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-05-16 15:18:24 +00:00
|
|
|
// CpuFeatures keeps track of which features are supported by the target CPU.
|
|
|
|
// Supported features must be enabled by a CpuFeatureScope before use.
|
|
|
|
// Example:
|
|
|
|
// if (assembler->IsSupported(SSE3)) {
|
|
|
|
// CpuFeatureScope fscope(assembler, SSE3);
|
|
|
|
// // Generate code containing SSE3 instructions.
|
|
|
|
// } else {
|
|
|
|
// // Generate alternative code.
|
|
|
|
// }
|
|
|
|
class CpuFeatures : public AllStatic {
|
2013-09-17 13:02:25 +00:00
|
|
|
public:
|
2014-05-16 15:18:24 +00:00
|
|
|
static void Probe(bool cross_compile) {
|
|
|
|
STATIC_ASSERT(NUMBER_OF_CPU_FEATURES <= kBitsPerInt);
|
|
|
|
if (initialized_) return;
|
|
|
|
initialized_ = true;
|
|
|
|
ProbeImpl(cross_compile);
|
|
|
|
}
|
|
|
|
|
2014-08-05 13:26:55 +00:00
|
|
|
static unsigned SupportedFeatures() {
|
|
|
|
Probe(false);
|
|
|
|
return supported_;
|
|
|
|
}
|
|
|
|
|
2014-05-16 15:18:24 +00:00
|
|
|
static bool IsSupported(CpuFeature f) {
|
|
|
|
return (supported_ & (1u << f)) != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool SupportsCrankshaft();
|
|
|
|
|
2016-03-16 13:49:39 +00:00
|
|
|
static inline unsigned cache_line_size() {
|
|
|
|
DCHECK(cache_line_size_ != 0);
|
|
|
|
return cache_line_size_;
|
2014-05-16 15:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void PrintTarget();
|
|
|
|
static void PrintFeatures();
|
2013-09-17 13:02:25 +00:00
|
|
|
|
2015-11-25 19:27:23 +00:00
|
|
|
private:
|
|
|
|
friend class ExternalReference;
|
|
|
|
friend class AssemblerBase;
|
2014-06-30 13:25:46 +00:00
|
|
|
// Flush instruction cache.
|
|
|
|
static void FlushICache(void* start, size_t size);
|
|
|
|
|
2014-05-16 15:18:24 +00:00
|
|
|
// Platform-dependent implementation.
|
|
|
|
static void ProbeImpl(bool cross_compile);
|
|
|
|
|
|
|
|
static unsigned supported_;
|
2016-03-16 13:49:39 +00:00
|
|
|
static unsigned cache_line_size_;
|
2014-05-16 15:18:24 +00:00
|
|
|
static bool initialized_;
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CpuFeatures);
|
2013-09-17 13:02:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Labels represent pc locations; they are typically jump or call targets.
|
|
|
|
// After declaration, a label can be freely used to denote known or (yet)
|
|
|
|
// unknown pc location. Assembler::bind() is used to bind a label to the
|
|
|
|
// current pc. A label can be bound only once.
|
|
|
|
|
2014-11-06 14:59:07 +00:00
|
|
|
class Label {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2011-05-10 09:03:42 +00:00
|
|
|
enum Distance {
|
|
|
|
kNear, kFar
|
|
|
|
};
|
|
|
|
|
|
|
|
INLINE(Label()) {
|
|
|
|
Unuse();
|
|
|
|
UnuseNear();
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-06-16 15:18:48 +00:00
|
|
|
INLINE(~Label()) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!is_linked());
|
|
|
|
DCHECK(!is_near_linked());
|
2011-06-16 15:18:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
INLINE(void Unuse()) { pos_ = 0; }
|
|
|
|
INLINE(void UnuseNear()) { near_link_pos_ = 0; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-06-16 15:18:48 +00:00
|
|
|
INLINE(bool is_bound() const) { return pos_ < 0; }
|
|
|
|
INLINE(bool is_unused() const) { return pos_ == 0 && near_link_pos_ == 0; }
|
|
|
|
INLINE(bool is_linked() const) { return pos_ > 0; }
|
2011-05-10 09:03:42 +00:00
|
|
|
INLINE(bool is_near_linked() const) { return near_link_pos_ > 0; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Returns the position of bound or linked labels. Cannot be used
|
|
|
|
// for unused labels.
|
|
|
|
int pos() const;
|
2011-05-10 09:03:42 +00:00
|
|
|
int near_link_pos() const { return near_link_pos_ - 1; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
// pos_ encodes both the binding state (via its sign)
|
|
|
|
// and the binding position (via its value) of a label.
|
|
|
|
//
|
|
|
|
// pos_ < 0 bound label, pos() returns the jump target position
|
|
|
|
// pos_ == 0 unused label
|
|
|
|
// pos_ > 0 linked label, pos() returns the last reference position
|
|
|
|
int pos_;
|
|
|
|
|
2011-05-10 09:03:42 +00:00
|
|
|
// Behaves like |pos_| in the "> 0" case, but for near jumps to this label.
|
|
|
|
int near_link_pos_;
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void bind_to(int pos) {
|
|
|
|
pos_ = -pos - 1;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_bound());
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-05-10 09:03:42 +00:00
|
|
|
void link_to(int pos, Distance distance = kFar) {
|
|
|
|
if (distance == kNear) {
|
|
|
|
near_link_pos_ = pos + 1;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_near_linked());
|
2011-05-10 09:03:42 +00:00
|
|
|
} else {
|
|
|
|
pos_ = pos + 1;
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_linked());
|
2011-05-10 09:03:42 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
friend class Assembler;
|
|
|
|
friend class Displacement;
|
2008-11-28 10:37:06 +00:00
|
|
|
friend class RegExpMacroAssemblerIrregexp;
|
2014-03-14 15:14:42 +00:00
|
|
|
|
2014-03-21 09:28:26 +00:00
|
|
|
#if V8_TARGET_ARCH_ARM64
|
|
|
|
// On ARM64, the Assembler keeps track of pointers to Labels to resolve
|
|
|
|
// branches to distant targets. Copying labels would confuse the Assembler.
|
2014-03-14 15:14:42 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(Label); // NOLINT
|
|
|
|
#endif
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
enum SaveFPRegsMode { kDontSaveFPRegs, kSaveFPRegs };
|
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
enum ArgvMode { kArgvOnStack, kArgvInRegister };
|
|
|
|
|
2014-05-20 09:21:45 +00:00
|
|
|
// Specifies whether to perform icache flush operations on RelocInfo updates.
|
|
|
|
// If FLUSH_ICACHE_IF_NEEDED, the icache will always be flushed if an
|
|
|
|
// instruction was modified. If SKIP_ICACHE_FLUSH the flush will always be
|
|
|
|
// skipped (only use this if you will flush the icache manually before it is
|
|
|
|
// executed).
|
|
|
|
enum ICacheFlushMode { FLUSH_ICACHE_IF_NEEDED, SKIP_ICACHE_FLUSH };
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Relocation information
|
|
|
|
|
2008-09-18 13:42:39 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Relocation information consists of the address (pc) of the datum
|
|
|
|
// to which the relocation information applies, the relocation mode
|
|
|
|
// (rmode), and an optional data field. The relocation mode may be
|
|
|
|
// "descriptive" and not indicate a need for relocation, but simply
|
|
|
|
// describe a property of the datum. Such rmodes are useful for GC
|
|
|
|
// and nice disassembly output.
|
|
|
|
|
2014-04-29 14:14:06 +00:00
|
|
|
class RelocInfo {
|
2008-07-03 15:10:15 +00:00
|
|
|
public:
|
2008-09-22 13:57:03 +00:00
|
|
|
// The constant kNoPosition is used with the collecting of source positions
|
|
|
|
// in the relocation information. Two types of source positions are collected
|
|
|
|
// "position" (RelocMode position) and "statement position" (RelocMode
|
|
|
|
// statement_position). The "position" is collected at places in the source
|
|
|
|
// code which are of interest when making stack traces to pin-point the source
|
|
|
|
// location of a stack frame as close as possible. The "statement position" is
|
|
|
|
// collected at the beginning at each statement, and is used to indicate
|
|
|
|
// possible break locations. kNoPosition is used to indicate an
|
|
|
|
// invalid/uninitialized position value.
|
|
|
|
static const int kNoPosition = -1;
|
|
|
|
|
2011-02-15 14:36:12 +00:00
|
|
|
// This string is used to add padding comments to the reloc info in cases
|
|
|
|
// where we are not sure to have enough space for patching in during
|
|
|
|
// lazy deoptimization. This is the case if we have indirect calls for which
|
|
|
|
// we do not normally record relocation info.
|
2011-08-05 11:32:46 +00:00
|
|
|
static const char* const kFillerCommentString;
|
2011-02-15 14:36:12 +00:00
|
|
|
|
2015-07-10 13:14:36 +00:00
|
|
|
// The minimum size of a comment is equal to two bytes for the extra tagged
|
|
|
|
// pc and kPointerSize for the actual pointer to the comment.
|
|
|
|
static const int kMinRelocCommentSize = 2 + kPointerSize;
|
2011-02-22 12:28:33 +00:00
|
|
|
|
|
|
|
// The maximum size for a call instruction including pc-jump.
|
|
|
|
static const int kMaxCallSize = 6;
|
|
|
|
|
2011-03-25 10:29:34 +00:00
|
|
|
// The maximum pc delta that will use the short encoding.
|
|
|
|
static const int kMaxSmallPCDelta;
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
enum Mode {
|
|
|
|
// Please note the order is important (see IsCodeTarget, IsGCRelocMode).
|
2011-04-27 15:02:59 +00:00
|
|
|
CODE_TARGET, // Code target which is not any of the above.
|
|
|
|
CODE_TARGET_WITH_ID,
|
2015-07-13 12:32:09 +00:00
|
|
|
DEBUGGER_STATEMENT, // Code target for the debugger statement.
|
2008-09-22 13:57:03 +00:00
|
|
|
EMBEDDED_OBJECT,
|
2013-06-12 15:03:44 +00:00
|
|
|
CELL,
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
// Everything after runtime_entry (inclusive) is not GC'ed.
|
|
|
|
RUNTIME_ENTRY,
|
|
|
|
COMMENT,
|
2015-02-05 14:51:45 +00:00
|
|
|
POSITION, // See comment for kNoPosition above.
|
2008-09-22 13:57:03 +00:00
|
|
|
STATEMENT_POSITION, // See comment for kNoPosition above.
|
2015-07-13 12:32:09 +00:00
|
|
|
|
|
|
|
// Additional code inserted for debug break slot.
|
|
|
|
DEBUG_BREAK_SLOT_AT_POSITION,
|
2015-07-15 09:22:33 +00:00
|
|
|
DEBUG_BREAK_SLOT_AT_RETURN,
|
2015-07-13 12:32:09 +00:00
|
|
|
DEBUG_BREAK_SLOT_AT_CALL,
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
EXTERNAL_REFERENCE, // The address of an external C++ function.
|
|
|
|
INTERNAL_REFERENCE, // An address inside the same function.
|
|
|
|
|
2015-03-13 10:07:54 +00:00
|
|
|
// Encoded internal reference, used only on MIPS, MIPS64 and PPC.
|
|
|
|
INTERNAL_REFERENCE_ENCODED,
|
|
|
|
|
2015-07-14 06:38:42 +00:00
|
|
|
// Continuation points for a generator yield.
|
|
|
|
GENERATOR_CONTINUATION,
|
|
|
|
|
2014-03-21 09:28:26 +00:00
|
|
|
// Marks constant and veneer pools. Only used on ARM and ARM64.
|
2014-03-12 15:40:41 +00:00
|
|
|
// They use a custom noncompact encoding.
|
2012-06-14 11:16:47 +00:00
|
|
|
CONST_POOL,
|
2014-03-12 15:40:41 +00:00
|
|
|
VENEER_POOL,
|
2012-06-14 11:16:47 +00:00
|
|
|
|
2015-07-13 12:32:09 +00:00
|
|
|
DEOPT_REASON, // Deoptimization reason index.
|
2015-07-10 13:14:36 +00:00
|
|
|
|
|
|
|
// This is not an actual reloc mode, but used to encode a long pc jump that
|
|
|
|
// cannot be encoded as part of another record.
|
|
|
|
PC_JUMP,
|
2015-02-05 14:51:45 +00:00
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
// Pseudo-types
|
2015-07-10 13:14:36 +00:00
|
|
|
NUMBER_OF_MODES,
|
2015-02-05 14:51:45 +00:00
|
|
|
NONE32, // never recorded 32-bit value
|
|
|
|
NONE64, // never recorded 64-bit value
|
2012-11-08 12:18:11 +00:00
|
|
|
CODE_AGE_SEQUENCE, // Not stored in RelocInfo array, used explictly by
|
|
|
|
// code aging.
|
2015-02-17 14:52:16 +00:00
|
|
|
|
2012-11-08 12:18:11 +00:00
|
|
|
FIRST_REAL_RELOC_MODE = CODE_TARGET,
|
2014-03-12 15:40:41 +00:00
|
|
|
LAST_REAL_RELOC_MODE = VENEER_POOL,
|
2015-07-13 12:32:09 +00:00
|
|
|
LAST_CODE_ENUM = DEBUGGER_STATEMENT,
|
2013-06-12 15:03:44 +00:00
|
|
|
LAST_GCED_ENUM = CELL,
|
2008-09-22 13:57:03 +00:00
|
|
|
};
|
|
|
|
|
2015-07-13 12:32:09 +00:00
|
|
|
STATIC_ASSERT(NUMBER_OF_MODES <= kBitsPerInt);
|
|
|
|
|
2015-11-27 12:18:38 +00:00
|
|
|
explicit RelocInfo(Isolate* isolate) : isolate_(isolate) {
|
|
|
|
DCHECK_NOT_NULL(isolate);
|
|
|
|
}
|
2011-09-19 18:36:47 +00:00
|
|
|
|
2015-11-27 12:18:38 +00:00
|
|
|
RelocInfo(Isolate* isolate, byte* pc, Mode rmode, intptr_t data, Code* host)
|
|
|
|
: isolate_(isolate), pc_(pc), rmode_(rmode), data_(data), host_(host) {
|
|
|
|
DCHECK_NOT_NULL(isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
2012-11-08 12:18:11 +00:00
|
|
|
static inline bool IsRealRelocMode(Mode mode) {
|
|
|
|
return mode >= FIRST_REAL_RELOC_MODE &&
|
|
|
|
mode <= LAST_REAL_RELOC_MODE;
|
|
|
|
}
|
2008-09-22 13:57:03 +00:00
|
|
|
static inline bool IsCodeTarget(Mode mode) {
|
|
|
|
return mode <= LAST_CODE_ENUM;
|
|
|
|
}
|
2011-10-12 15:43:41 +00:00
|
|
|
static inline bool IsEmbeddedObject(Mode mode) {
|
|
|
|
return mode == EMBEDDED_OBJECT;
|
|
|
|
}
|
2015-04-10 13:54:09 +00:00
|
|
|
static inline bool IsCell(Mode mode) { return mode == CELL; }
|
2013-03-11 14:11:03 +00:00
|
|
|
static inline bool IsRuntimeEntry(Mode mode) {
|
|
|
|
return mode == RUNTIME_ENTRY;
|
|
|
|
}
|
2008-09-22 13:57:03 +00:00
|
|
|
// Is the relocation mode affected by GC?
|
|
|
|
static inline bool IsGCRelocMode(Mode mode) {
|
|
|
|
return mode <= LAST_GCED_ENUM;
|
|
|
|
}
|
|
|
|
static inline bool IsComment(Mode mode) {
|
|
|
|
return mode == COMMENT;
|
|
|
|
}
|
2012-06-14 11:16:47 +00:00
|
|
|
static inline bool IsConstPool(Mode mode) {
|
|
|
|
return mode == CONST_POOL;
|
|
|
|
}
|
2014-03-12 15:40:41 +00:00
|
|
|
static inline bool IsVeneerPool(Mode mode) {
|
|
|
|
return mode == VENEER_POOL;
|
|
|
|
}
|
2015-02-11 17:11:23 +00:00
|
|
|
static inline bool IsDeoptReason(Mode mode) {
|
|
|
|
return mode == DEOPT_REASON;
|
|
|
|
}
|
2008-09-22 13:57:03 +00:00
|
|
|
static inline bool IsPosition(Mode mode) {
|
|
|
|
return mode == POSITION || mode == STATEMENT_POSITION;
|
|
|
|
}
|
|
|
|
static inline bool IsStatementPosition(Mode mode) {
|
|
|
|
return mode == STATEMENT_POSITION;
|
|
|
|
}
|
|
|
|
static inline bool IsExternalReference(Mode mode) {
|
|
|
|
return mode == EXTERNAL_REFERENCE;
|
|
|
|
}
|
|
|
|
static inline bool IsInternalReference(Mode mode) {
|
|
|
|
return mode == INTERNAL_REFERENCE;
|
|
|
|
}
|
2015-02-17 14:52:16 +00:00
|
|
|
static inline bool IsInternalReferenceEncoded(Mode mode) {
|
|
|
|
return mode == INTERNAL_REFERENCE_ENCODED;
|
|
|
|
}
|
2010-06-08 12:04:49 +00:00
|
|
|
static inline bool IsDebugBreakSlot(Mode mode) {
|
2015-07-15 09:22:33 +00:00
|
|
|
return IsDebugBreakSlotAtPosition(mode) || IsDebugBreakSlotAtReturn(mode) ||
|
2015-12-02 14:13:39 +00:00
|
|
|
IsDebugBreakSlotAtCall(mode);
|
2015-07-13 12:32:09 +00:00
|
|
|
}
|
|
|
|
static inline bool IsDebugBreakSlotAtPosition(Mode mode) {
|
|
|
|
return mode == DEBUG_BREAK_SLOT_AT_POSITION;
|
|
|
|
}
|
2015-07-15 09:22:33 +00:00
|
|
|
static inline bool IsDebugBreakSlotAtReturn(Mode mode) {
|
|
|
|
return mode == DEBUG_BREAK_SLOT_AT_RETURN;
|
|
|
|
}
|
2015-07-13 12:32:09 +00:00
|
|
|
static inline bool IsDebugBreakSlotAtCall(Mode mode) {
|
|
|
|
return mode == DEBUG_BREAK_SLOT_AT_CALL;
|
|
|
|
}
|
2015-03-04 13:15:07 +00:00
|
|
|
static inline bool IsDebuggerStatement(Mode mode) {
|
2015-07-13 12:32:09 +00:00
|
|
|
return mode == DEBUGGER_STATEMENT;
|
2015-03-04 13:15:07 +00:00
|
|
|
}
|
2012-12-28 13:34:15 +00:00
|
|
|
static inline bool IsNone(Mode mode) {
|
2013-01-04 10:56:24 +00:00
|
|
|
return mode == NONE32 || mode == NONE64;
|
2012-12-28 13:34:15 +00:00
|
|
|
}
|
2012-11-08 12:18:11 +00:00
|
|
|
static inline bool IsCodeAgeSequence(Mode mode) {
|
|
|
|
return mode == CODE_AGE_SEQUENCE;
|
|
|
|
}
|
2015-07-14 06:38:42 +00:00
|
|
|
static inline bool IsGeneratorContinuation(Mode mode) {
|
|
|
|
return mode == GENERATOR_CONTINUATION;
|
|
|
|
}
|
2008-09-22 13:57:03 +00:00
|
|
|
static inline int ModeMask(Mode mode) { return 1 << mode; }
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Accessors
|
2015-11-27 12:18:38 +00:00
|
|
|
Isolate* isolate() const { return isolate_; }
|
2010-09-24 08:25:31 +00:00
|
|
|
byte* pc() const { return pc_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
void set_pc(byte* pc) { pc_ = pc; }
|
2008-09-22 13:57:03 +00:00
|
|
|
Mode rmode() const { return rmode_; }
|
2010-09-24 08:25:31 +00:00
|
|
|
intptr_t data() const { return data_; }
|
2011-09-19 18:36:47 +00:00
|
|
|
Code* host() const { return host_; }
|
2014-03-12 17:18:49 +00:00
|
|
|
void set_host(Code* host) { host_ = host; }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2015-07-15 09:22:33 +00:00
|
|
|
// Apply a relocation by delta bytes. When the code object is moved, PC
|
|
|
|
// relative addresses have to be updated as well as absolute addresses
|
|
|
|
// inside the code (internal references).
|
|
|
|
// Do not forget to flush the icache afterwards!
|
|
|
|
INLINE(void apply(intptr_t delta));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-05-20 13:54:31 +00:00
|
|
|
// Is the pointer this relocation info refers to coded like a plain pointer
|
2012-01-16 12:38:59 +00:00
|
|
|
// or is it strange in some way (e.g. relative or patched into a series of
|
2010-05-20 13:54:31 +00:00
|
|
|
// instructions).
|
|
|
|
bool IsCodedSpecially();
|
|
|
|
|
2014-03-10 18:47:57 +00:00
|
|
|
// If true, the pointer this relocation info refers to is an entry in the
|
|
|
|
// constant pool, otherwise the pointer is embedded in the instruction stream.
|
|
|
|
bool IsInConstantPool();
|
|
|
|
|
2009-01-13 14:38:12 +00:00
|
|
|
// this relocation applies to;
|
2013-03-13 11:40:26 +00:00
|
|
|
// can only be called if IsCodeTarget(rmode_) || IsRuntimeEntry(rmode_)
|
2008-07-03 15:10:15 +00:00
|
|
|
INLINE(Address target_address());
|
2011-10-21 10:37:56 +00:00
|
|
|
INLINE(void set_target_address(Address target,
|
2014-05-20 09:21:45 +00:00
|
|
|
WriteBarrierMode write_barrier_mode =
|
|
|
|
UPDATE_WRITE_BARRIER,
|
|
|
|
ICacheFlushMode icache_flush_mode =
|
|
|
|
FLUSH_ICACHE_IF_NEEDED));
|
2008-07-03 15:10:15 +00:00
|
|
|
INLINE(Object* target_object());
|
2009-10-06 13:11:05 +00:00
|
|
|
INLINE(Handle<Object> target_object_handle(Assembler* origin));
|
2011-10-21 10:37:56 +00:00
|
|
|
INLINE(void set_target_object(Object* target,
|
2014-05-20 09:21:45 +00:00
|
|
|
WriteBarrierMode write_barrier_mode =
|
|
|
|
UPDATE_WRITE_BARRIER,
|
|
|
|
ICacheFlushMode icache_flush_mode =
|
|
|
|
FLUSH_ICACHE_IF_NEEDED));
|
2013-03-11 14:11:03 +00:00
|
|
|
INLINE(Address target_runtime_entry(Assembler* origin));
|
|
|
|
INLINE(void set_target_runtime_entry(Address target,
|
2014-05-20 09:21:45 +00:00
|
|
|
WriteBarrierMode write_barrier_mode =
|
|
|
|
UPDATE_WRITE_BARRIER,
|
|
|
|
ICacheFlushMode icache_flush_mode =
|
|
|
|
FLUSH_ICACHE_IF_NEEDED));
|
2013-06-12 15:03:44 +00:00
|
|
|
INLINE(Cell* target_cell());
|
|
|
|
INLINE(Handle<Cell> target_cell_handle());
|
|
|
|
INLINE(void set_target_cell(Cell* cell,
|
2014-05-20 09:21:45 +00:00
|
|
|
WriteBarrierMode write_barrier_mode =
|
|
|
|
UPDATE_WRITE_BARRIER,
|
|
|
|
ICacheFlushMode icache_flush_mode =
|
|
|
|
FLUSH_ICACHE_IF_NEEDED));
|
2013-10-23 13:48:04 +00:00
|
|
|
INLINE(Handle<Object> code_age_stub_handle(Assembler* origin));
|
2012-11-08 12:18:11 +00:00
|
|
|
INLINE(Code* code_age_stub());
|
2014-05-20 09:21:45 +00:00
|
|
|
INLINE(void set_code_age_stub(Code* stub,
|
|
|
|
ICacheFlushMode icache_flush_mode =
|
|
|
|
FLUSH_ICACHE_IF_NEEDED));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2014-03-10 18:47:57 +00:00
|
|
|
// Returns the address of the constant pool entry where the target address
|
|
|
|
// is held. This should only be called if IsInConstantPool returns true.
|
|
|
|
INLINE(Address constant_pool_entry_address());
|
|
|
|
|
2010-05-26 08:34:07 +00:00
|
|
|
// Read the address of the word containing the target_address in an
|
|
|
|
// instruction stream. What this means exactly is architecture-independent.
|
|
|
|
// The only architecture-independent user of this function is the serializer.
|
|
|
|
// The serializer uses it to find out how many raw bytes of instruction to
|
|
|
|
// output before the next target. Architecture-independent code shouldn't
|
|
|
|
// dereference the pointer it gets back from this.
|
2009-01-13 14:38:12 +00:00
|
|
|
INLINE(Address target_address_address());
|
2014-03-10 18:47:57 +00:00
|
|
|
|
2010-05-26 08:34:07 +00:00
|
|
|
// This indicates how much space a target takes up when deserializing a code
|
|
|
|
// stream. For most architectures this is just the size of a pointer. For
|
|
|
|
// an instruction like movw/movt where the target bits are mixed into the
|
|
|
|
// instruction bits the size of the target will be zero, indicating that the
|
|
|
|
// serializer should not step forwards in memory after a target is resolved
|
|
|
|
// and written. In this case the target_address_address function above
|
|
|
|
// should return the end of the instructions to be patched, allowing the
|
|
|
|
// deserializer to deserialize the instructions as raw bytes and put them in
|
|
|
|
// place, ready to be patched with the target.
|
|
|
|
INLINE(int target_address_size());
|
2009-01-13 14:38:12 +00:00
|
|
|
|
2015-03-05 13:46:31 +00:00
|
|
|
// Read the reference in the instruction this relocation
|
|
|
|
// applies to; can only be called if rmode_ is EXTERNAL_REFERENCE.
|
|
|
|
INLINE(Address target_external_reference());
|
|
|
|
|
2015-03-18 13:38:32 +00:00
|
|
|
// Read the reference in the instruction this relocation
|
2015-03-05 13:46:31 +00:00
|
|
|
// applies to; can only be called if rmode_ is INTERNAL_REFERENCE.
|
|
|
|
INLINE(Address target_internal_reference());
|
2015-03-18 13:38:32 +00:00
|
|
|
|
|
|
|
// Return the reference address this relocation applies to;
|
|
|
|
// can only be called if rmode_ is INTERNAL_REFERENCE.
|
|
|
|
INLINE(Address target_internal_reference_address());
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Read/modify the address of a call instruction. This is used to relocate
|
|
|
|
// the break points where straight-line code is patched with a call
|
|
|
|
// instruction.
|
2015-07-15 09:22:33 +00:00
|
|
|
INLINE(Address debug_call_address());
|
|
|
|
INLINE(void set_debug_call_address(Address target));
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-11-05 10:14:48 +00:00
|
|
|
// Wipe out a relocation to a fixed value, used for making snapshots
|
|
|
|
// reproducible.
|
|
|
|
INLINE(void WipeOut());
|
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
template<typename StaticVisitor> inline void Visit(Heap* heap);
|
2013-09-11 10:51:06 +00:00
|
|
|
inline void Visit(Isolate* isolate, ObjectVisitor* v);
|
2010-05-26 08:34:07 +00:00
|
|
|
|
2010-06-08 12:04:49 +00:00
|
|
|
// Check whether this debug break slot has been patched with a call to the
|
|
|
|
// debugger.
|
2016-02-10 14:19:31 +00:00
|
|
|
bool IsPatchedDebugBreakSlotSequence();
|
2010-06-08 12:04:49 +00:00
|
|
|
|
2013-02-20 13:12:26 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Check whether the given code contains relocation information that
|
|
|
|
// either is position-relative or movable by the garbage collector.
|
|
|
|
static bool RequiresRelocation(const CodeDesc& desc);
|
|
|
|
#endif
|
|
|
|
|
2008-08-06 10:02:49 +00:00
|
|
|
#ifdef ENABLE_DISASSEMBLER
|
|
|
|
// Printing
|
2008-09-22 13:57:03 +00:00
|
|
|
static const char* RelocModeName(Mode rmode);
|
2014-09-30 10:29:32 +00:00
|
|
|
void Print(Isolate* isolate, std::ostream& os); // NOLINT
|
2008-08-06 10:02:49 +00:00
|
|
|
#endif // ENABLE_DISASSEMBLER
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2014-05-06 11:25:37 +00:00
|
|
|
void Verify(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif
|
|
|
|
|
2008-09-22 13:57:03 +00:00
|
|
|
static const int kCodeTargetMask = (1 << (LAST_CODE_ENUM + 1)) - 1;
|
|
|
|
static const int kPositionMask = 1 << POSITION | 1 << STATEMENT_POSITION;
|
2011-04-27 15:02:59 +00:00
|
|
|
static const int kDataMask =
|
|
|
|
(1 << CODE_TARGET_WITH_ID) | kPositionMask | (1 << COMMENT);
|
2015-12-02 14:13:39 +00:00
|
|
|
static const int kDebugBreakSlotMask = 1 << DEBUG_BREAK_SLOT_AT_POSITION |
|
|
|
|
1 << DEBUG_BREAK_SLOT_AT_RETURN |
|
|
|
|
1 << DEBUG_BREAK_SLOT_AT_CALL;
|
2015-07-15 09:22:33 +00:00
|
|
|
static const int kApplyMask; // Modes affected by apply. Depends on arch.
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2015-11-27 12:18:38 +00:00
|
|
|
Isolate* isolate_;
|
2008-07-03 15:10:15 +00:00
|
|
|
// On ARM, note that pc_ is the address of the constant pool entry
|
|
|
|
// to be relocated and not the address of the instruction
|
|
|
|
// referencing the constant pool entry (except when rmode_ ==
|
|
|
|
// comment).
|
|
|
|
byte* pc_;
|
2008-09-22 13:57:03 +00:00
|
|
|
Mode rmode_;
|
2015-06-04 14:44:00 +00:00
|
|
|
intptr_t data_;
|
2011-09-19 18:36:47 +00:00
|
|
|
Code* host_;
|
2008-07-03 15:10:15 +00:00
|
|
|
friend class RelocIterator;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// RelocInfoWriter serializes a stream of relocation info. It writes towards
|
|
|
|
// lower addresses.
|
|
|
|
class RelocInfoWriter BASE_EMBEDDED {
|
|
|
|
public:
|
2015-02-12 12:15:14 +00:00
|
|
|
RelocInfoWriter()
|
|
|
|
: pos_(NULL),
|
|
|
|
last_pc_(NULL),
|
|
|
|
last_id_(0),
|
|
|
|
last_position_(0),
|
|
|
|
last_mode_(RelocInfo::NUMBER_OF_MODES),
|
|
|
|
next_position_candidate_pos_delta_(0),
|
|
|
|
next_position_candidate_pc_delta_(0),
|
|
|
|
next_position_candidate_flushed_(true) {}
|
|
|
|
RelocInfoWriter(byte* pos, byte* pc)
|
|
|
|
: pos_(pos),
|
|
|
|
last_pc_(pc),
|
|
|
|
last_id_(0),
|
|
|
|
last_position_(0),
|
|
|
|
last_mode_(RelocInfo::NUMBER_OF_MODES),
|
|
|
|
next_position_candidate_pos_delta_(0),
|
|
|
|
next_position_candidate_pc_delta_(0),
|
|
|
|
next_position_candidate_flushed_(true) {}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
byte* pos() const { return pos_; }
|
|
|
|
byte* last_pc() const { return last_pc_; }
|
|
|
|
|
|
|
|
void Write(const RelocInfo* rinfo);
|
|
|
|
|
|
|
|
// Update the state of the stream after reloc info buffer
|
|
|
|
// and/or code is moved while the stream is active.
|
|
|
|
void Reposition(byte* pos, byte* pc) {
|
|
|
|
pos_ = pos;
|
|
|
|
last_pc_ = pc;
|
|
|
|
}
|
|
|
|
|
2015-02-12 12:15:14 +00:00
|
|
|
void Finish() { FlushPosition(); }
|
|
|
|
|
2009-06-23 09:50:51 +00:00
|
|
|
// Max size (bytes) of a written RelocInfo. Longest encoding is
|
2015-07-10 13:14:36 +00:00
|
|
|
// ExtraTag, VariableLengthPCJump, ExtraTag, pc_delta, data_delta.
|
|
|
|
// On ia32 and arm this is 1 + 4 + 1 + 1 + 4 = 11.
|
|
|
|
// On x64 this is 1 + 4 + 1 + 1 + 8 == 15;
|
2009-06-23 09:50:51 +00:00
|
|
|
// Here we use the maximum of the two.
|
2015-07-10 13:14:36 +00:00
|
|
|
static const int kMaxSize = 15;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
private:
|
2015-07-10 13:14:36 +00:00
|
|
|
inline uint32_t WriteLongPCJump(uint32_t pc_delta);
|
|
|
|
|
|
|
|
inline void WriteShortTaggedPC(uint32_t pc_delta, int tag);
|
|
|
|
inline void WriteShortTaggedData(intptr_t data_delta, int tag);
|
|
|
|
|
|
|
|
inline void WriteMode(RelocInfo::Mode rmode);
|
|
|
|
inline void WriteModeAndPC(uint32_t pc_delta, RelocInfo::Mode rmode);
|
|
|
|
inline void WriteIntData(int data_delta);
|
|
|
|
inline void WriteData(intptr_t data_delta);
|
2015-02-12 12:15:14 +00:00
|
|
|
inline void WritePosition(int pc_delta, int pos_delta, RelocInfo::Mode rmode);
|
|
|
|
|
|
|
|
void FlushPosition();
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
byte* pos_;
|
|
|
|
byte* last_pc_;
|
2011-04-27 15:02:59 +00:00
|
|
|
int last_id_;
|
|
|
|
int last_position_;
|
2015-02-12 12:15:14 +00:00
|
|
|
RelocInfo::Mode last_mode_;
|
|
|
|
int next_position_candidate_pos_delta_;
|
|
|
|
uint32_t next_position_candidate_pc_delta_;
|
|
|
|
bool next_position_candidate_flushed_;
|
|
|
|
|
2008-08-28 09:55:41 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RelocInfoWriter);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// A RelocIterator iterates over relocation information.
|
|
|
|
// Typical use:
|
|
|
|
//
|
|
|
|
// for (RelocIterator it(code); !it.done(); it.next()) {
|
|
|
|
// // do something with it.rinfo() here
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// A mask can be specified to skip unwanted modes.
|
|
|
|
class RelocIterator: public Malloced {
|
|
|
|
public:
|
|
|
|
// Create a new iterator positioned at
|
|
|
|
// the beginning of the reloc info.
|
|
|
|
// Relocation information with mode k is included in the
|
|
|
|
// iteration iff bit k of mode_mask is set.
|
|
|
|
explicit RelocIterator(Code* code, int mode_mask = -1);
|
|
|
|
explicit RelocIterator(const CodeDesc& desc, int mode_mask = -1);
|
|
|
|
|
|
|
|
// Iteration
|
2010-09-24 08:25:31 +00:00
|
|
|
bool done() const { return done_; }
|
2008-07-03 15:10:15 +00:00
|
|
|
void next();
|
|
|
|
|
|
|
|
// Return pointer valid until next next().
|
|
|
|
RelocInfo* rinfo() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(!done());
|
2008-07-03 15:10:15 +00:00
|
|
|
return &rinfo_;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Advance* moves the position before/after reading.
|
|
|
|
// *Read* reads from current byte(s) into rinfo_.
|
|
|
|
// *Get* just reads and returns info on current byte.
|
|
|
|
void Advance(int bytes = 1) { pos_ -= bytes; }
|
|
|
|
int AdvanceGetTag();
|
2015-07-10 13:14:36 +00:00
|
|
|
RelocInfo::Mode GetMode();
|
|
|
|
|
|
|
|
void AdvanceReadLongPCJump();
|
|
|
|
|
|
|
|
int GetShortDataTypeTag();
|
|
|
|
void ReadShortTaggedPC();
|
|
|
|
void ReadShortTaggedId();
|
|
|
|
void ReadShortTaggedPosition();
|
|
|
|
void ReadShortTaggedData();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
void AdvanceReadPC();
|
2011-04-27 15:02:59 +00:00
|
|
|
void AdvanceReadId();
|
2015-07-10 08:49:14 +00:00
|
|
|
void AdvanceReadInt();
|
2011-04-27 15:02:59 +00:00
|
|
|
void AdvanceReadPosition();
|
2008-07-03 15:10:15 +00:00
|
|
|
void AdvanceReadData();
|
|
|
|
|
|
|
|
// If the given mode is wanted, set it in rinfo_ and return true.
|
|
|
|
// Else return false. Used for efficiently skipping unwanted modes.
|
2008-09-22 13:57:03 +00:00
|
|
|
bool SetMode(RelocInfo::Mode mode) {
|
2010-11-30 10:55:24 +00:00
|
|
|
return (mode_mask_ & (1 << mode)) ? (rinfo_.rmode_ = mode, true) : false;
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
byte* pos_;
|
|
|
|
byte* end_;
|
2012-11-08 12:18:11 +00:00
|
|
|
byte* code_age_sequence_;
|
2008-07-03 15:10:15 +00:00
|
|
|
RelocInfo rinfo_;
|
|
|
|
bool done_;
|
|
|
|
int mode_mask_;
|
2011-04-27 15:02:59 +00:00
|
|
|
int last_id_;
|
|
|
|
int last_position_;
|
2008-08-28 09:55:41 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(RelocIterator);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// External function
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
class SCTableReference;
|
2009-04-20 16:36:13 +00:00
|
|
|
class Debug_Address;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-06-09 09:26:53 +00:00
|
|
|
|
|
|
|
// An ExternalReference represents a C++ address used in the generated
|
|
|
|
// code. All references to C++ functions and variables must be encapsulated in
|
|
|
|
// an ExternalReference instance. This is done in order to track the origin of
|
|
|
|
// all external references in the code so that they can be bound to the correct
|
|
|
|
// addresses when deserializing a heap.
|
2008-07-03 15:10:15 +00:00
|
|
|
class ExternalReference BASE_EMBEDDED {
|
|
|
|
public:
|
2011-02-04 13:43:38 +00:00
|
|
|
// Used in the simulator to support different native api calls.
|
|
|
|
enum Type {
|
2011-02-24 15:39:09 +00:00
|
|
|
// Builtin call.
|
2016-01-22 18:34:32 +00:00
|
|
|
// Object* f(v8::internal::Arguments).
|
2011-02-04 13:43:38 +00:00
|
|
|
BUILTIN_CALL, // default
|
2011-02-24 15:39:09 +00:00
|
|
|
|
2016-01-22 18:34:32 +00:00
|
|
|
// Builtin call returning object pair.
|
|
|
|
// ObjectPair f(v8::internal::Arguments).
|
|
|
|
BUILTIN_CALL_PAIR,
|
|
|
|
|
2016-01-15 14:34:38 +00:00
|
|
|
// Builtin call that returns .
|
|
|
|
// ObjectTriple f(v8::internal::Arguments).
|
|
|
|
BUILTIN_CALL_TRIPLE,
|
|
|
|
|
2011-04-27 14:29:25 +00:00
|
|
|
// Builtin that takes float arguments and returns an int.
|
|
|
|
// int f(double, double).
|
|
|
|
BUILTIN_COMPARE_CALL,
|
|
|
|
|
2011-02-24 15:39:09 +00:00
|
|
|
// Builtin call that returns floating point.
|
|
|
|
// double f(double, double).
|
2011-04-27 14:29:25 +00:00
|
|
|
BUILTIN_FP_FP_CALL,
|
|
|
|
|
|
|
|
// Builtin call that returns floating point.
|
|
|
|
// double f(double).
|
|
|
|
BUILTIN_FP_CALL,
|
|
|
|
|
|
|
|
// Builtin call that returns floating point.
|
|
|
|
// double f(double, int).
|
|
|
|
BUILTIN_FP_INT_CALL,
|
2011-02-24 15:39:09 +00:00
|
|
|
|
|
|
|
// Direct call to API function callback.
|
2013-08-27 13:41:44 +00:00
|
|
|
// void f(v8::FunctionCallbackInfo&)
|
2011-02-24 15:39:09 +00:00
|
|
|
DIRECT_API_CALL,
|
|
|
|
|
2013-06-13 19:16:35 +00:00
|
|
|
// Call to function callback via InvokeFunctionCallback.
|
2013-08-27 13:41:44 +00:00
|
|
|
// void f(v8::FunctionCallbackInfo&, v8::FunctionCallback)
|
|
|
|
PROFILING_API_CALL,
|
2013-06-13 19:16:35 +00:00
|
|
|
|
2011-02-24 15:39:09 +00:00
|
|
|
// Direct call to accessor getter callback.
|
2014-08-20 15:25:13 +00:00
|
|
|
// void f(Local<Name> property, PropertyCallbackInfo& info)
|
2013-05-21 12:17:04 +00:00
|
|
|
DIRECT_GETTER_CALL,
|
|
|
|
|
2013-06-13 19:16:35 +00:00
|
|
|
// Call to accessor getter callback via InvokeAccessorGetterCallback.
|
2014-08-20 15:25:13 +00:00
|
|
|
// void f(Local<Name> property, PropertyCallbackInfo& info,
|
|
|
|
// AccessorNameGetterCallback callback)
|
2013-08-27 13:41:44 +00:00
|
|
|
PROFILING_GETTER_CALL
|
2011-02-04 13:43:38 +00:00
|
|
|
};
|
|
|
|
|
2012-04-05 14:10:39 +00:00
|
|
|
static void SetUp();
|
2012-11-26 13:12:35 +00:00
|
|
|
static void InitializeMathExpData();
|
|
|
|
static void TearDownMathExpData();
|
2012-04-05 14:10:39 +00:00
|
|
|
|
2015-11-23 08:09:34 +00:00
|
|
|
typedef void* ExternalReferenceRedirector(Isolate* isolate, void* original,
|
|
|
|
Type type);
|
2011-02-04 13:43:38 +00:00
|
|
|
|
2013-07-29 13:56:51 +00:00
|
|
|
ExternalReference() : address_(NULL) {}
|
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference(Builtins::CFunctionId id, Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference(ApiFunction* ptr, Type type, Isolate* isolate);
|
2009-11-04 08:51:48 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference(Builtins::Name name, Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference(Runtime::FunctionId id, Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference(const Runtime::Function* f, Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
explicit ExternalReference(StatsCounter* counter);
|
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
ExternalReference(Isolate::AddressId id, Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
explicit ExternalReference(const SCTableReference& table_ref);
|
|
|
|
|
2013-09-02 09:27:27 +00:00
|
|
|
// Isolate as an external reference.
|
2013-04-24 07:39:35 +00:00
|
|
|
static ExternalReference isolate_address(Isolate* isolate);
|
2011-03-18 20:35:07 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// One-of-a-kind references. These references are not part of a general
|
|
|
|
// pattern. This means that they have to be added to the
|
|
|
|
// ExternalReferenceTable in serialize.cc manually.
|
|
|
|
|
2016-02-05 14:32:38 +00:00
|
|
|
static ExternalReference interpreter_dispatch_table_address(Isolate* isolate);
|
|
|
|
|
2011-09-19 18:36:47 +00:00
|
|
|
static ExternalReference incremental_marking_record_write_function(
|
|
|
|
Isolate* isolate);
|
2016-02-04 08:15:52 +00:00
|
|
|
static ExternalReference incremental_marking_record_write_code_entry_function(
|
|
|
|
Isolate* isolate);
|
2011-09-19 18:36:47 +00:00
|
|
|
static ExternalReference store_buffer_overflow_function(
|
|
|
|
Isolate* isolate);
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference delete_handle_scope_extensions(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-03-09 12:07:29 +00:00
|
|
|
static ExternalReference get_date_field_function(Isolate* isolate);
|
|
|
|
static ExternalReference date_cache_stamp(Isolate* isolate);
|
|
|
|
|
2012-11-08 12:18:11 +00:00
|
|
|
static ExternalReference get_make_code_young_function(Isolate* isolate);
|
2013-10-23 13:48:04 +00:00
|
|
|
static ExternalReference get_mark_code_as_executed_function(Isolate* isolate);
|
2012-11-08 12:18:11 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Deoptimization support.
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference new_deoptimizer_function(Isolate* isolate);
|
|
|
|
static ExternalReference compute_output_frames_function(Isolate* isolate);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2016-03-04 09:50:48 +00:00
|
|
|
static ExternalReference wasm_f32_trunc(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f32_floor(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f32_ceil(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f32_nearest_int(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f64_trunc(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f64_floor(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f64_ceil(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_f64_nearest_int(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_int64_to_float32(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_uint64_to_float32(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_int64_to_float64(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_uint64_to_float64(Isolate* isolate);
|
2016-03-14 10:13:49 +00:00
|
|
|
static ExternalReference wasm_float32_to_int64(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_float32_to_uint64(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_float64_to_int64(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_float64_to_uint64(Isolate* isolate);
|
2016-03-15 06:51:53 +00:00
|
|
|
static ExternalReference wasm_int64_div(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_int64_mod(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_uint64_div(Isolate* isolate);
|
|
|
|
static ExternalReference wasm_uint64_mod(Isolate* isolate);
|
2016-02-02 10:57:58 +00:00
|
|
|
|
2016-03-03 01:22:01 +00:00
|
|
|
static ExternalReference f64_acos_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_asin_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_atan_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_cos_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_sin_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_tan_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_exp_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_log_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_atan2_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_pow_wrapper_function(Isolate* isolate);
|
|
|
|
static ExternalReference f64_mod_wrapper_function(Isolate* isolate);
|
|
|
|
|
2012-11-28 15:11:21 +00:00
|
|
|
// Log support.
|
|
|
|
static ExternalReference log_enter_external_function(Isolate* isolate);
|
|
|
|
static ExternalReference log_leave_external_function(Isolate* isolate);
|
|
|
|
|
2009-12-10 15:10:50 +00:00
|
|
|
// Static data in the keyed lookup cache.
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference keyed_lookup_cache_keys(Isolate* isolate);
|
|
|
|
static ExternalReference keyed_lookup_cache_field_offsets(Isolate* isolate);
|
2009-12-10 15:10:50 +00:00
|
|
|
|
2011-10-20 12:27:10 +00:00
|
|
|
// Static variable Heap::roots_array_start()
|
|
|
|
static ExternalReference roots_array_start(Isolate* isolate);
|
2009-08-24 11:57:57 +00:00
|
|
|
|
2013-07-17 11:50:24 +00:00
|
|
|
// Static variable Heap::allocation_sites_list_address()
|
|
|
|
static ExternalReference allocation_sites_list_address(Isolate* isolate);
|
|
|
|
|
2009-02-12 09:29:02 +00:00
|
|
|
// Static variable StackGuard::address_of_jslimit()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference address_of_stack_limit(Isolate* isolate);
|
2009-11-05 13:59:40 +00:00
|
|
|
|
|
|
|
// Static variable StackGuard::address_of_real_jslimit()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference address_of_real_stack_limit(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-01-12 13:05:23 +00:00
|
|
|
// Static variable RegExpStack::limit_address()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference address_of_regexp_stack_limit(Isolate* isolate);
|
2009-01-12 13:05:23 +00:00
|
|
|
|
2010-01-06 11:09:30 +00:00
|
|
|
// Static variables for RegExp.
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference address_of_static_offsets_vector(Isolate* isolate);
|
|
|
|
static ExternalReference address_of_regexp_stack_memory_address(
|
|
|
|
Isolate* isolate);
|
|
|
|
static ExternalReference address_of_regexp_stack_memory_size(
|
|
|
|
Isolate* isolate);
|
2010-01-06 11:09:30 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Static variable Heap::NewSpaceStart()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference new_space_start(Isolate* isolate);
|
2011-09-19 18:36:47 +00:00
|
|
|
|
|
|
|
// Write barrier.
|
|
|
|
static ExternalReference store_buffer_top(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Used for fast allocation in generated code.
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference new_space_allocation_top_address(Isolate* isolate);
|
|
|
|
static ExternalReference new_space_allocation_limit_address(Isolate* isolate);
|
2015-04-07 11:31:57 +00:00
|
|
|
static ExternalReference old_space_allocation_top_address(Isolate* isolate);
|
|
|
|
static ExternalReference old_space_allocation_limit_address(Isolate* isolate);
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2013-12-18 10:40:26 +00:00
|
|
|
static ExternalReference mod_two_doubles_operation(Isolate* isolate);
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference power_double_double_function(Isolate* isolate);
|
|
|
|
static ExternalReference power_double_int_function(Isolate* isolate);
|
2009-04-16 09:30:23 +00:00
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static ExternalReference handle_scope_next_address(Isolate* isolate);
|
|
|
|
static ExternalReference handle_scope_limit_address(Isolate* isolate);
|
|
|
|
static ExternalReference handle_scope_level_address(Isolate* isolate);
|
2009-11-04 08:51:48 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference scheduled_exception_address(Isolate* isolate);
|
2012-06-11 13:18:05 +00:00
|
|
|
static ExternalReference address_of_pending_message_obj(Isolate* isolate);
|
2009-11-04 08:51:48 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Static variables containing common double constants.
|
|
|
|
static ExternalReference address_of_min_int();
|
|
|
|
static ExternalReference address_of_one_half();
|
2013-02-27 14:44:57 +00:00
|
|
|
static ExternalReference address_of_minus_one_half();
|
2010-12-08 14:32:40 +00:00
|
|
|
static ExternalReference address_of_negative_infinity();
|
2011-07-13 13:50:27 +00:00
|
|
|
static ExternalReference address_of_the_hole_nan();
|
2013-10-15 16:12:25 +00:00
|
|
|
static ExternalReference address_of_uint32_bias();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference math_log_double_function(Isolate* isolate);
|
2011-03-02 14:40:38 +00:00
|
|
|
|
2012-11-26 13:12:35 +00:00
|
|
|
static ExternalReference math_exp_constants(int constant_index);
|
|
|
|
static ExternalReference math_exp_log_table();
|
|
|
|
|
2012-06-06 11:05:28 +00:00
|
|
|
static ExternalReference page_flags(Page* page);
|
|
|
|
|
2012-12-18 16:25:45 +00:00
|
|
|
static ExternalReference ForDeoptEntry(Address entry);
|
|
|
|
|
2013-01-23 16:29:48 +00:00
|
|
|
static ExternalReference cpu_features();
|
|
|
|
|
2014-06-23 07:10:25 +00:00
|
|
|
static ExternalReference debug_is_active_address(Isolate* isolate);
|
2014-05-22 07:57:33 +00:00
|
|
|
static ExternalReference debug_after_break_target_address(Isolate* isolate);
|
|
|
|
|
2014-04-28 08:26:35 +00:00
|
|
|
static ExternalReference is_profiling_address(Isolate* isolate);
|
|
|
|
static ExternalReference invoke_function_callback(Isolate* isolate);
|
|
|
|
static ExternalReference invoke_accessor_getter_callback(Isolate* isolate);
|
|
|
|
|
2015-10-12 07:34:18 +00:00
|
|
|
static ExternalReference virtual_handler_register(Isolate* isolate);
|
|
|
|
static ExternalReference virtual_slot_register(Isolate* isolate);
|
2015-09-15 10:14:11 +00:00
|
|
|
|
2015-10-02 18:13:41 +00:00
|
|
|
static ExternalReference runtime_function_table_address(Isolate* isolate);
|
|
|
|
|
2013-07-29 13:56:51 +00:00
|
|
|
Address address() const { return reinterpret_cast<Address>(address_); }
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-04-20 16:36:13 +00:00
|
|
|
// Used to check if single stepping is enabled in generated code.
|
2015-12-01 10:53:43 +00:00
|
|
|
static ExternalReference debug_step_in_enabled_address(Isolate* isolate);
|
2009-04-20 16:36:13 +00:00
|
|
|
|
2010-04-19 19:30:11 +00:00
|
|
|
#ifndef V8_INTERPRETED_REGEXP
|
2009-08-31 12:40:37 +00:00
|
|
|
// C functions called from RegExp generated code.
|
|
|
|
|
|
|
|
// Function NativeRegExpMacroAssembler::CaseInsensitiveCompareUC16()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference re_case_insensitive_compare_uc16(Isolate* isolate);
|
2009-08-31 12:40:37 +00:00
|
|
|
|
|
|
|
// Function RegExpMacroAssembler*::CheckStackGuardState()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference re_check_stack_guard_state(Isolate* isolate);
|
2009-08-31 12:40:37 +00:00
|
|
|
|
|
|
|
// Function NativeRegExpMacroAssembler::GrowStack()
|
2011-03-22 13:20:04 +00:00
|
|
|
static ExternalReference re_grow_stack(Isolate* isolate);
|
2010-01-18 09:49:50 +00:00
|
|
|
|
|
|
|
// byte NativeRegExpMacroAssembler::word_character_bitmap
|
|
|
|
static ExternalReference re_word_character_map();
|
|
|
|
|
2009-08-31 12:40:37 +00:00
|
|
|
#endif
|
|
|
|
|
2009-06-09 09:26:53 +00:00
|
|
|
// This lets you register a function that rewrites all external references.
|
|
|
|
// Used by the ARM simulator to catch calls to external references.
|
2011-05-05 18:55:31 +00:00
|
|
|
static void set_redirector(Isolate* isolate,
|
|
|
|
ExternalReferenceRedirector* redirector) {
|
2011-03-18 20:35:07 +00:00
|
|
|
// We can't stack them.
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(isolate->external_reference_redirector() == NULL);
|
2011-05-05 18:55:31 +00:00
|
|
|
isolate->set_external_reference_redirector(
|
2011-03-18 20:35:07 +00:00
|
|
|
reinterpret_cast<ExternalReferenceRedirectorPointer*>(redirector));
|
2009-06-09 09:26:53 +00:00
|
|
|
}
|
|
|
|
|
2013-07-18 08:12:01 +00:00
|
|
|
static ExternalReference stress_deopt_count(Isolate* isolate);
|
|
|
|
|
2015-07-22 10:25:51 +00:00
|
|
|
static ExternalReference fixed_typed_array_base_data_offset();
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
private:
|
|
|
|
explicit ExternalReference(void* address)
|
2009-06-09 09:26:53 +00:00
|
|
|
: address_(address) {}
|
|
|
|
|
2011-03-22 13:20:04 +00:00
|
|
|
static void* Redirect(Isolate* isolate,
|
|
|
|
Address address_arg,
|
2011-02-04 13:43:38 +00:00
|
|
|
Type type = ExternalReference::BUILTIN_CALL) {
|
2011-03-18 20:35:07 +00:00
|
|
|
ExternalReferenceRedirector* redirector =
|
|
|
|
reinterpret_cast<ExternalReferenceRedirector*>(
|
2011-03-22 13:20:04 +00:00
|
|
|
isolate->external_reference_redirector());
|
2009-06-09 09:26:53 +00:00
|
|
|
void* address = reinterpret_cast<void*>(address_arg);
|
2015-11-23 08:09:34 +00:00
|
|
|
void* answer =
|
|
|
|
(redirector == NULL) ? address : (*redirector)(isolate, address, type);
|
2009-11-16 12:08:40 +00:00
|
|
|
return answer;
|
2009-06-09 09:26:53 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2009-06-09 09:26:53 +00:00
|
|
|
void* address_;
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
2014-10-07 13:30:28 +00:00
|
|
|
bool operator==(ExternalReference, ExternalReference);
|
|
|
|
bool operator!=(ExternalReference, ExternalReference);
|
|
|
|
|
|
|
|
size_t hash_value(ExternalReference);
|
|
|
|
|
|
|
|
std::ostream& operator<<(std::ostream&, ExternalReference);
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-11-04 15:12:03 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Position recording support
|
|
|
|
|
2010-11-30 13:17:36 +00:00
|
|
|
struct PositionState {
|
|
|
|
PositionState() : current_position(RelocInfo::kNoPosition),
|
|
|
|
written_position(RelocInfo::kNoPosition),
|
|
|
|
current_statement_position(RelocInfo::kNoPosition),
|
|
|
|
written_statement_position(RelocInfo::kNoPosition) {}
|
|
|
|
|
|
|
|
int current_position;
|
|
|
|
int written_position;
|
|
|
|
|
|
|
|
int current_statement_position;
|
|
|
|
int written_statement_position;
|
|
|
|
};
|
|
|
|
|
2016-03-02 02:10:03 +00:00
|
|
|
class AssemblerPositionsRecorder : public PositionsRecorder {
|
2010-11-04 15:12:03 +00:00
|
|
|
public:
|
2016-03-02 02:10:03 +00:00
|
|
|
explicit AssemblerPositionsRecorder(Assembler* assembler)
|
|
|
|
: assembler_(assembler) {}
|
2010-11-30 13:17:36 +00:00
|
|
|
|
|
|
|
// Set current position to pos.
|
|
|
|
void RecordPosition(int pos);
|
2010-11-04 15:12:03 +00:00
|
|
|
|
|
|
|
// Set current statement position to pos.
|
|
|
|
void RecordStatementPosition(int pos);
|
|
|
|
|
|
|
|
// Write recorded positions to relocation information.
|
|
|
|
bool WriteRecordedPositions();
|
|
|
|
|
2010-11-30 13:17:36 +00:00
|
|
|
int current_position() const { return state_.current_position; }
|
2010-11-04 15:12:03 +00:00
|
|
|
|
2010-11-30 13:17:36 +00:00
|
|
|
int current_statement_position() const {
|
|
|
|
return state_.current_statement_position;
|
|
|
|
}
|
2010-11-04 15:12:03 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Assembler* assembler_;
|
2010-11-30 13:17:36 +00:00
|
|
|
PositionState state_;
|
2010-11-04 15:12:03 +00:00
|
|
|
|
2016-03-02 02:10:03 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(AssemblerPositionsRecorder);
|
2010-11-04 15:12:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Utility functions
|
|
|
|
|
2011-11-29 10:56:11 +00:00
|
|
|
inline int NumberOfBitsSet(uint32_t x) {
|
2010-02-04 20:36:58 +00:00
|
|
|
unsigned int num_bits_set;
|
|
|
|
for (num_bits_set = 0; x; x >>= 1) {
|
|
|
|
num_bits_set += x & 1;
|
|
|
|
}
|
|
|
|
return num_bits_set;
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2010-12-08 14:32:40 +00:00
|
|
|
// Computes pow(x, y) with the special cases in the spec for Math.pow.
|
2015-11-25 16:37:11 +00:00
|
|
|
double power_helper(Isolate* isolate, double x, double y);
|
2010-12-08 14:32:40 +00:00
|
|
|
double power_double_int(double x, int y);
|
|
|
|
double power_double_double(double x, double y);
|
|
|
|
|
2011-05-03 09:30:06 +00:00
|
|
|
// Helper class for generating code or data associated with the code
|
|
|
|
// right after a call instruction. As an example this can be used to
|
|
|
|
// generate safepoint data after calls for crankshaft.
|
|
|
|
class CallWrapper {
|
|
|
|
public:
|
|
|
|
CallWrapper() { }
|
|
|
|
virtual ~CallWrapper() { }
|
|
|
|
// Called just before emitting a call. Argument is the size of the generated
|
|
|
|
// call code.
|
2011-05-03 15:12:40 +00:00
|
|
|
virtual void BeforeCall(int call_size) const = 0;
|
2011-05-03 09:30:06 +00:00
|
|
|
// Called just after emitting a call, i.e., at the return site for the call.
|
2011-05-03 15:12:40 +00:00
|
|
|
virtual void AfterCall() const = 0;
|
2015-11-26 14:12:04 +00:00
|
|
|
// Return whether call needs to check for debug stepping.
|
|
|
|
virtual bool NeedsDebugStepCheck() const { return false; }
|
2011-05-03 15:12:40 +00:00
|
|
|
};
|
|
|
|
|
2015-11-26 14:12:04 +00:00
|
|
|
|
2011-05-03 15:12:40 +00:00
|
|
|
class NullCallWrapper : public CallWrapper {
|
|
|
|
public:
|
|
|
|
NullCallWrapper() { }
|
|
|
|
virtual ~NullCallWrapper() { }
|
|
|
|
virtual void BeforeCall(int call_size) const { }
|
|
|
|
virtual void AfterCall() const { }
|
2011-05-03 09:30:06 +00:00
|
|
|
};
|
|
|
|
|
2014-03-10 10:39:17 +00:00
|
|
|
|
2015-11-26 14:12:04 +00:00
|
|
|
class CheckDebugStepCallWrapper : public CallWrapper {
|
|
|
|
public:
|
|
|
|
CheckDebugStepCallWrapper() {}
|
|
|
|
virtual ~CheckDebugStepCallWrapper() {}
|
|
|
|
virtual void BeforeCall(int call_size) const {}
|
|
|
|
virtual void AfterCall() const {}
|
|
|
|
virtual bool NeedsDebugStepCheck() const { return true; }
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-06-04 14:44:00 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Constant pool support
|
|
|
|
|
|
|
|
class ConstantPoolEntry {
|
|
|
|
public:
|
|
|
|
ConstantPoolEntry() {}
|
|
|
|
ConstantPoolEntry(int position, intptr_t value, bool sharing_ok)
|
|
|
|
: position_(position),
|
|
|
|
merged_index_(sharing_ok ? SHARING_ALLOWED : SHARING_PROHIBITED),
|
|
|
|
value_(value) {}
|
|
|
|
ConstantPoolEntry(int position, double value)
|
|
|
|
: position_(position), merged_index_(SHARING_ALLOWED), value64_(value) {}
|
|
|
|
|
|
|
|
int position() const { return position_; }
|
|
|
|
bool sharing_ok() const { return merged_index_ != SHARING_PROHIBITED; }
|
|
|
|
bool is_merged() const { return merged_index_ >= 0; }
|
|
|
|
int merged_index(void) const {
|
|
|
|
DCHECK(is_merged());
|
|
|
|
return merged_index_;
|
|
|
|
}
|
|
|
|
void set_merged_index(int index) {
|
|
|
|
merged_index_ = index;
|
|
|
|
DCHECK(is_merged());
|
|
|
|
}
|
|
|
|
int offset(void) const {
|
|
|
|
DCHECK(merged_index_ >= 0);
|
|
|
|
return merged_index_;
|
|
|
|
}
|
|
|
|
void set_offset(int offset) {
|
|
|
|
DCHECK(offset >= 0);
|
|
|
|
merged_index_ = offset;
|
|
|
|
}
|
|
|
|
intptr_t value() const { return value_; }
|
|
|
|
uint64_t value64() const { return bit_cast<uint64_t>(value64_); }
|
|
|
|
|
|
|
|
enum Type { INTPTR, DOUBLE, NUMBER_OF_TYPES };
|
|
|
|
|
|
|
|
static int size(Type type) {
|
|
|
|
return (type == INTPTR) ? kPointerSize : kDoubleSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
enum Access { REGULAR, OVERFLOWED };
|
|
|
|
|
|
|
|
private:
|
|
|
|
int position_;
|
|
|
|
int merged_index_;
|
|
|
|
union {
|
|
|
|
intptr_t value_;
|
|
|
|
double value64_;
|
|
|
|
};
|
|
|
|
enum { SHARING_PROHIBITED = -2, SHARING_ALLOWED = -1 };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Embedded constant pool support
|
|
|
|
|
|
|
|
class ConstantPoolBuilder BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
ConstantPoolBuilder(int ptr_reach_bits, int double_reach_bits);
|
|
|
|
|
|
|
|
// Add pointer-sized constant to the embedded constant pool
|
|
|
|
ConstantPoolEntry::Access AddEntry(int position, intptr_t value,
|
|
|
|
bool sharing_ok) {
|
|
|
|
ConstantPoolEntry entry(position, value, sharing_ok);
|
|
|
|
return AddEntry(entry, ConstantPoolEntry::INTPTR);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add double constant to the embedded constant pool
|
|
|
|
ConstantPoolEntry::Access AddEntry(int position, double value) {
|
|
|
|
ConstantPoolEntry entry(position, value);
|
|
|
|
return AddEntry(entry, ConstantPoolEntry::DOUBLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Previews the access type required for the next new entry to be added.
|
|
|
|
ConstantPoolEntry::Access NextAccess(ConstantPoolEntry::Type type) const;
|
|
|
|
|
|
|
|
bool IsEmpty() {
|
|
|
|
return info_[ConstantPoolEntry::INTPTR].entries.empty() &&
|
|
|
|
info_[ConstantPoolEntry::INTPTR].shared_entries.empty() &&
|
|
|
|
info_[ConstantPoolEntry::DOUBLE].entries.empty() &&
|
|
|
|
info_[ConstantPoolEntry::DOUBLE].shared_entries.empty();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit the constant pool. Invoke only after all entries have been
|
|
|
|
// added and all instructions have been emitted.
|
|
|
|
// Returns position of the emitted pool (zero implies no constant pool).
|
|
|
|
int Emit(Assembler* assm);
|
|
|
|
|
|
|
|
// Returns the label associated with the start of the constant pool.
|
|
|
|
// Linking to this label in the function prologue may provide an
|
|
|
|
// efficient means of constant pool pointer register initialization
|
|
|
|
// on some architectures.
|
|
|
|
inline Label* EmittedPosition() { return &emitted_label_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ConstantPoolEntry::Access AddEntry(ConstantPoolEntry& entry,
|
|
|
|
ConstantPoolEntry::Type type);
|
|
|
|
void EmitSharedEntries(Assembler* assm, ConstantPoolEntry::Type type);
|
|
|
|
void EmitGroup(Assembler* assm, ConstantPoolEntry::Access access,
|
|
|
|
ConstantPoolEntry::Type type);
|
|
|
|
|
|
|
|
struct PerTypeEntryInfo {
|
|
|
|
PerTypeEntryInfo() : regular_count(0), overflow_start(-1) {}
|
|
|
|
bool overflow() const {
|
|
|
|
return (overflow_start >= 0 &&
|
|
|
|
overflow_start < static_cast<int>(entries.size()));
|
|
|
|
}
|
|
|
|
int regular_reach_bits;
|
|
|
|
int regular_count;
|
|
|
|
int overflow_start;
|
|
|
|
std::vector<ConstantPoolEntry> entries;
|
|
|
|
std::vector<ConstantPoolEntry> shared_entries;
|
|
|
|
};
|
|
|
|
|
|
|
|
Label emitted_label_; // Records pc_offset of emitted pool
|
|
|
|
PerTypeEntryInfo info_[ConstantPoolEntry::NUMBER_OF_TYPES];
|
|
|
|
};
|
|
|
|
|
2015-09-30 13:46:56 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2008-07-03 15:10:15 +00:00
|
|
|
#endif // V8_ASSEMBLER_H_
|