2011-02-02 13:55:29 +00:00
|
|
|
// Copyright 2011 the V8 project authors. All rights reserved.
|
2014-04-29 06:42:26 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
#ifndef V8_SAFEPOINT_TABLE_H_
|
|
|
|
#define V8_SAFEPOINT_TABLE_H_
|
|
|
|
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/allocation.h"
|
2014-08-05 08:18:22 +00:00
|
|
|
#include "src/heap/heap.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "src/v8memory.h"
|
|
|
|
#include "src/zone.h"
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
struct Register;
|
|
|
|
|
|
|
|
class SafepointEntry BASE_EMBEDDED {
|
2010-12-07 11:31:57 +00:00
|
|
|
public:
|
2014-09-15 09:21:39 +00:00
|
|
|
SafepointEntry() : info_(0), bits_(NULL) {}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-15 09:21:39 +00:00
|
|
|
SafepointEntry(unsigned info, uint8_t* bits) : info_(info), bits_(bits) {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_valid());
|
2011-01-12 14:14:14 +00:00
|
|
|
}
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
bool is_valid() const { return bits_ != NULL; }
|
|
|
|
|
|
|
|
bool Equals(const SafepointEntry& other) const {
|
|
|
|
return info_ == other.info_ && bits_ == other.bits_;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
void Reset() {
|
|
|
|
info_ = 0;
|
|
|
|
bits_ = NULL;
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
int deoptimization_index() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_valid());
|
2011-01-12 14:14:14 +00:00
|
|
|
return DeoptimizationIndexField::decode(info_);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-11-16 08:44:30 +00:00
|
|
|
static const int kArgumentsFieldBits = 3;
|
|
|
|
static const int kSaveDoublesFieldBits = 1;
|
|
|
|
static const int kDeoptIndexBits =
|
|
|
|
32 - kArgumentsFieldBits - kSaveDoublesFieldBits;
|
|
|
|
class DeoptimizationIndexField:
|
|
|
|
public BitField<int, 0, kDeoptIndexBits> {}; // NOLINT
|
|
|
|
class ArgumentsField:
|
|
|
|
public BitField<unsigned,
|
|
|
|
kDeoptIndexBits,
|
|
|
|
kArgumentsFieldBits> {}; // NOLINT
|
|
|
|
class SaveDoublesField:
|
|
|
|
public BitField<bool,
|
|
|
|
kDeoptIndexBits + kArgumentsFieldBits,
|
|
|
|
kSaveDoublesFieldBits> { }; // NOLINT
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
int argument_count() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_valid());
|
2011-01-12 14:14:14 +00:00
|
|
|
return ArgumentsField::decode(info_);
|
|
|
|
}
|
|
|
|
|
2011-01-14 08:49:52 +00:00
|
|
|
bool has_doubles() const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_valid());
|
2011-01-14 08:49:52 +00:00
|
|
|
return SaveDoublesField::decode(info_);
|
|
|
|
}
|
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
uint8_t* bits() {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(is_valid());
|
2011-01-12 14:14:14 +00:00
|
|
|
return bits_;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool HasRegisters() const;
|
|
|
|
bool HasRegisterAt(int reg_index) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
unsigned info_;
|
|
|
|
uint8_t* bits_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SafepointTable BASE_EMBEDDED {
|
|
|
|
public:
|
|
|
|
explicit SafepointTable(Code* code);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
int size() const {
|
|
|
|
return kHeaderSize +
|
2014-09-15 09:21:39 +00:00
|
|
|
(length_ * (kPcAndDeoptimizationIndexSize + entry_size_));
|
2014-08-25 07:02:19 +00:00
|
|
|
}
|
2011-01-12 14:14:14 +00:00
|
|
|
unsigned length() const { return length_; }
|
|
|
|
unsigned entry_size() const { return entry_size_; }
|
|
|
|
|
|
|
|
unsigned GetPcOffset(unsigned index) const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(index < length_);
|
2011-01-12 14:14:14 +00:00
|
|
|
return Memory::uint32_at(GetPcOffsetLocation(index));
|
|
|
|
}
|
|
|
|
|
|
|
|
SafepointEntry GetEntry(unsigned index) const {
|
2014-08-04 11:34:54 +00:00
|
|
|
DCHECK(index < length_);
|
2011-01-12 14:14:14 +00:00
|
|
|
unsigned info = Memory::uint32_at(GetInfoLocation(index));
|
|
|
|
uint8_t* bits = &Memory::uint8_at(entries_ + (index * entry_size_));
|
2014-09-15 09:21:39 +00:00
|
|
|
return SafepointEntry(info, bits);
|
2011-01-12 14:14:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Returns the entry for the given pc.
|
|
|
|
SafepointEntry FindEntry(Address pc) const;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
void PrintEntry(unsigned index, std::ostream& os) const; // NOLINT
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
static const uint8_t kNoRegisters = 0xFF;
|
|
|
|
|
|
|
|
static const int kLengthOffset = 0;
|
|
|
|
static const int kEntrySizeOffset = kLengthOffset + kIntSize;
|
|
|
|
static const int kHeaderSize = kEntrySizeOffset + kIntSize;
|
|
|
|
|
|
|
|
static const int kPcSize = kIntSize;
|
|
|
|
static const int kDeoptimizationIndexSize = kIntSize;
|
2014-09-15 09:21:39 +00:00
|
|
|
static const int kPcAndDeoptimizationIndexSize =
|
|
|
|
kPcSize + kDeoptimizationIndexSize;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
Address GetPcOffsetLocation(unsigned index) const {
|
|
|
|
return pc_and_deoptimization_indexes_ +
|
2014-09-15 09:21:39 +00:00
|
|
|
(index * kPcAndDeoptimizationIndexSize);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 14:14:14 +00:00
|
|
|
Address GetInfoLocation(unsigned index) const {
|
2010-12-07 11:31:57 +00:00
|
|
|
return GetPcOffsetLocation(index) + kPcSize;
|
|
|
|
}
|
|
|
|
|
2014-09-30 10:29:32 +00:00
|
|
|
static void PrintBits(std::ostream& os, // NOLINT
|
2014-07-07 09:57:29 +00:00
|
|
|
uint8_t byte, int digits);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-06-03 15:32:22 +00:00
|
|
|
DisallowHeapAllocation no_allocation_;
|
2010-12-07 11:31:57 +00:00
|
|
|
Code* code_;
|
|
|
|
unsigned length_;
|
|
|
|
unsigned entry_size_;
|
|
|
|
|
|
|
|
Address pc_and_deoptimization_indexes_;
|
|
|
|
Address entries_;
|
|
|
|
|
|
|
|
friend class SafepointTableBuilder;
|
2011-01-12 14:14:14 +00:00
|
|
|
friend class SafepointEntry;
|
|
|
|
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(SafepointTable);
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class Safepoint BASE_EMBEDDED {
|
|
|
|
public:
|
2011-01-26 20:48:48 +00:00
|
|
|
typedef enum {
|
|
|
|
kSimple = 0,
|
|
|
|
kWithRegisters = 1 << 0,
|
|
|
|
kWithDoubles = 1 << 1,
|
|
|
|
kWithRegistersAndDoubles = kWithRegisters | kWithDoubles
|
|
|
|
} Kind;
|
|
|
|
|
2011-11-16 08:44:30 +00:00
|
|
|
enum DeoptMode {
|
|
|
|
kNoLazyDeopt,
|
|
|
|
kLazyDeopt
|
|
|
|
};
|
|
|
|
|
2011-01-10 19:43:38 +00:00
|
|
|
static const int kNoDeoptimizationIndex =
|
2011-01-12 14:14:14 +00:00
|
|
|
(1 << (SafepointEntry::kDeoptIndexBits)) - 1;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-06-04 14:42:58 +00:00
|
|
|
void DefinePointerSlot(int index, Zone* zone) { indexes_->Add(index, zone); }
|
2012-06-11 12:42:31 +00:00
|
|
|
void DefinePointerRegister(Register reg, Zone* zone);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
private:
|
2014-09-15 09:21:39 +00:00
|
|
|
Safepoint(ZoneList<int>* indexes, ZoneList<int>* registers)
|
|
|
|
: indexes_(indexes), registers_(registers) {}
|
2010-12-07 11:31:57 +00:00
|
|
|
ZoneList<int>* indexes_;
|
|
|
|
ZoneList<int>* registers_;
|
|
|
|
|
|
|
|
friend class SafepointTableBuilder;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SafepointTableBuilder BASE_EMBEDDED {
|
|
|
|
public:
|
2012-06-04 14:42:58 +00:00
|
|
|
explicit SafepointTableBuilder(Zone* zone)
|
|
|
|
: deoptimization_info_(32, zone),
|
|
|
|
deopt_index_list_(32, zone),
|
|
|
|
indexes_(32, zone),
|
|
|
|
registers_(32, zone),
|
2011-11-16 08:44:30 +00:00
|
|
|
emitted_(false),
|
2012-06-04 14:42:58 +00:00
|
|
|
last_lazy_safepoint_(0),
|
|
|
|
zone_(zone) { }
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Get the offset of the emitted safepoint table in the code.
|
|
|
|
unsigned GetCodeOffset() const;
|
|
|
|
|
|
|
|
// Define a new safepoint for the current position in the body.
|
2011-02-02 13:55:29 +00:00
|
|
|
Safepoint DefineSafepoint(Assembler* assembler,
|
|
|
|
Safepoint::Kind kind,
|
|
|
|
int arguments,
|
2011-11-16 08:44:30 +00:00
|
|
|
Safepoint::DeoptMode mode);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2011-11-16 08:44:30 +00:00
|
|
|
// Record deoptimization index for lazy deoptimization for the last
|
|
|
|
// outstanding safepoints.
|
|
|
|
void RecordLazyDeoptimizationIndex(int index);
|
2014-03-12 09:59:36 +00:00
|
|
|
void BumpLastLazySafepointIndex() {
|
|
|
|
last_lazy_safepoint_ = deopt_index_list_.length();
|
|
|
|
}
|
2011-03-08 11:21:38 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
// Emit the safepoint table after the body. The number of bits per
|
|
|
|
// entry must be enough to hold all the pointer indexes.
|
|
|
|
void Emit(Assembler* assembler, int bits_per_entry);
|
|
|
|
|
2011-02-04 14:09:03 +00:00
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
private:
|
|
|
|
struct DeoptimizationInfo {
|
|
|
|
unsigned pc;
|
2011-01-12 14:14:14 +00:00
|
|
|
unsigned arguments;
|
2011-01-14 08:49:52 +00:00
|
|
|
bool has_doubles;
|
2010-12-07 11:31:57 +00:00
|
|
|
};
|
|
|
|
|
2011-11-16 08:44:30 +00:00
|
|
|
uint32_t EncodeExceptPC(const DeoptimizationInfo& info, unsigned index);
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
ZoneList<DeoptimizationInfo> deoptimization_info_;
|
2011-11-16 08:44:30 +00:00
|
|
|
ZoneList<unsigned> deopt_index_list_;
|
2010-12-07 11:31:57 +00:00
|
|
|
ZoneList<ZoneList<int>*> indexes_;
|
|
|
|
ZoneList<ZoneList<int>*> registers_;
|
|
|
|
|
|
|
|
unsigned offset_;
|
2011-02-04 14:09:03 +00:00
|
|
|
bool emitted_;
|
2011-11-16 08:44:30 +00:00
|
|
|
int last_lazy_safepoint_;
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2012-06-04 14:42:58 +00:00
|
|
|
Zone* zone_;
|
|
|
|
|
2010-12-07 11:31:57 +00:00
|
|
|
DISALLOW_COPY_AND_ASSIGN(SafepointTableBuilder);
|
|
|
|
};
|
|
|
|
|
|
|
|
} } // namespace v8::internal
|
|
|
|
|
|
|
|
#endif // V8_SAFEPOINT_TABLE_H_
|