Commit 142fe343 authored by lrn@chromium.org's avatar lrn@chromium.org

X64: General fixes - added inline definitions and changed some places to intptr_t.

Review URL: http://codereview.chromium.org/113199


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1913 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2b7616dc
......@@ -43,9 +43,10 @@ namespace v8 { namespace internal {
void Disassembler::Dump(FILE* f, byte* begin, byte* end) {
for (byte* pc = begin; pc < end; pc++) {
if (f == NULL) {
PrintF("%p %4d %02x\n", pc, pc - begin, *pc);
PrintF("%" V8PRIxPTR " %4" V8PRIdPTR " %02x\n", pc, pc - begin, *pc);
} else {
fprintf(f, "%p %4d %02x\n", pc, pc - begin, *pc);
fprintf(f, "%" V8PRIxPTR " %4" V8PRIdPTR " %02x\n",
reinterpret_cast<uintptr_t>(pc), pc - begin, *pc);
}
}
}
......@@ -144,8 +145,8 @@ static int DecodeIt(FILE* f,
// raw pointer embedded in code stream, e.g., jump table
byte* ptr = *reinterpret_cast<byte**>(pc);
OS::SNPrintF(decode_buffer,
"%08x jump table entry %4d",
reinterpret_cast<int32_t>(ptr),
"%08" V8PRIxPTR " jump table entry %4" V8PRIdPTR,
ptr,
ptr - begin);
pc += 4;
} else {
......
......@@ -86,7 +86,8 @@ typedef byte* Address;
#define V8_PTR_PREFIX ""
#endif
#define V8PRIp V8_PTR_PREFIX "x"
#define V8PRIxPTR V8_PTR_PREFIX "x"
#define V8PRIdPTR V8_PTR_PREFIX "d"
// Code-point values in Unicode 4.0 are 21 bits wide.
typedef uint16_t uc16;
......
......@@ -46,7 +46,7 @@ void CPU::FlushICache(void* start, size_t size) {
// is patched on an intel CPU the core performing the patching will have its
// own instruction cache updated automatically.
// If flushing of the instruction cache becomes necessary Windows have the
// If flushing of the instruction cache becomes necessary Windows has the
// API function FlushInstructionCache.
}
......
......@@ -631,7 +631,7 @@ void Logger::HandleEvent(const char* name, Object** location) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_handles) return;
LogMessageBuilder msg;
msg.Append("%s,0x%%"V8PRIp"\n", name, location);
msg.Append("%s,0x%%" V8PRIxPTR "\n", name, location);
msg.WriteToLogFile();
#endif
}
......@@ -850,7 +850,7 @@ void Logger::NewEvent(const char* name, void* object, size_t size) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log) return;
LogMessageBuilder msg;
msg.Append("new,%s,0x%%"V8PRIp",%u\n", name, object,
msg.Append("new,%s,0x%%" V8PRIxPTR ",%u\n", name, object,
static_cast<unsigned int>(size));
msg.WriteToLogFile();
#endif
......@@ -861,7 +861,7 @@ void Logger::DeleteEvent(const char* name, void* object) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log) return;
LogMessageBuilder msg;
msg.Append("delete,%s,0x%%"V8PRIp"\n", name, object);
msg.Append("delete,%s,0x%%" V8PRIxPTR "\n", name, object);
msg.WriteToLogFile();
#endif
}
......@@ -871,7 +871,7 @@ void Logger::CodeCreateEvent(const char* tag, Code* code, const char* comment) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_code) return;
LogMessageBuilder msg;
msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"", tag, code->address(),
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"", tag, code->address(),
code->ExecutableSize());
for (const char* p = comment; *p != '\0'; p++) {
if (*p == '"') {
......@@ -892,8 +892,8 @@ void Logger::CodeCreateEvent(const char* tag, Code* code, String* name) {
LogMessageBuilder msg;
SmartPointer<char> str =
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"%s\"\n", tag, code->address(),
code->ExecutableSize(), *str);
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"%s\"\n",
tag, code->address(), code->ExecutableSize(), *str);
msg.WriteToLogFile();
#endif
}
......@@ -908,7 +908,7 @@ void Logger::CodeCreateEvent(const char* tag, Code* code, String* name,
name->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
SmartPointer<char> sourcestr =
source->ToCString(DISALLOW_NULLS, ROBUST_STRING_TRAVERSAL);
msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"%s %s:%d\"\n",
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"%s %s:%d\"\n",
tag, code->address(),
code->ExecutableSize(),
*str, *sourcestr, line);
......@@ -921,7 +921,7 @@ void Logger::CodeCreateEvent(const char* tag, Code* code, int args_count) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_code) return;
LogMessageBuilder msg;
msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"args_count: %d\"\n", tag,
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"args_count: %d\"\n", tag,
code->address(),
code->ExecutableSize(),
args_count);
......@@ -934,7 +934,7 @@ void Logger::RegExpCodeCreateEvent(Code* code, String* source) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_code) return;
LogMessageBuilder msg;
msg.Append("code-creation,%s,0x%"V8PRIp",%d,\"", "RegExp",
msg.Append("code-creation,%s,0x%" V8PRIxPTR ",%d,\"", "RegExp",
code->address(),
code->ExecutableSize());
msg.AppendDetailed(source, false);
......@@ -948,7 +948,9 @@ void Logger::CodeAllocateEvent(Code* code, Assembler* assem) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_code) return;
LogMessageBuilder msg;
msg.Append("code-allocate,0x%"V8PRIp",0x%"V8PRIp"\n", code->address(), assem);
msg.Append("code-allocate,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n",
code->address(),
assem);
msg.WriteToLogFile();
#endif
}
......@@ -958,7 +960,7 @@ void Logger::CodeMoveEvent(Address from, Address to) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_code) return;
LogMessageBuilder msg;
msg.Append("code-move,0x%"V8PRIp",0x%"V8PRIp"\n", from, to);
msg.Append("code-move,0x%" V8PRIxPTR ",0x%" V8PRIxPTR "\n", from, to);
msg.WriteToLogFile();
#endif
}
......@@ -968,7 +970,7 @@ void Logger::CodeDeleteEvent(Address from) {
#ifdef ENABLE_LOGGING_AND_PROFILING
if (!Log::is_enabled() || !FLAG_log_code) return;
LogMessageBuilder msg;
msg.Append("code-delete,0x%"V8PRIp"\n", from);
msg.Append("code-delete,0x%" V8PRIxPTR "\n", from);
msg.WriteToLogFile();
#endif
}
......@@ -1074,13 +1076,13 @@ void Logger::DebugEvent(const char* event_type, Vector<uint16_t> parameter) {
void Logger::TickEvent(TickSample* sample, bool overflow) {
if (!Log::is_enabled() || !FLAG_prof) return;
LogMessageBuilder msg;
msg.Append("tick,0x%"V8PRIp",0x%"V8PRIp",%d", sample->pc, sample->sp,
static_cast<int>(sample->state));
msg.Append("tick,0x%" V8PRIxPTR ",0x%" V8PRIxPTR ",%d",
sample->pc, sample->sp, static_cast<int>(sample->state));
if (overflow) {
msg.Append(",overflow");
}
for (int i = 0; i < sample->frames_count; ++i) {
msg.Append(",0x%"V8PRIp, sample->stack[i]);
msg.Append(",0x%" V8PRIxPTR, sample->stack[i]);
}
msg.Append('\n');
msg.WriteToLogFile();
......
......@@ -6725,7 +6725,10 @@ class MapNameKey : public HashTableKey {
virtual HashFunction GetHashFunction() { return MapNameHash; }
static uint32_t MapNameHashHelper(Map* map, String* name) {
return reinterpret_cast<uint32_t>(map) ^ name->Hash();
// Uses only lower 32 bits if pointers are larger.
uintptr_t addr_hash =
static_cast<uint32_t>(reinterpret_cast<uintptr_t>(map));
return addr_hash ^ name->Hash();
}
static uint32_t MapNameHash(Object* obj) {
......
......@@ -4442,10 +4442,16 @@ static Object* Runtime_LookupContext(Arguments args) {
// compiler to do the right thing.
//
// TODO(1236026): This is a non-portable hack that should be removed.
// TODO(x64): Definitely!
typedef uint64_t ObjectPair;
static inline ObjectPair MakePair(Object* x, Object* y) {
#if V8_HOST_ARCH_64_BIT
UNIMPLEMENTED();
return 0;
#else
return reinterpret_cast<uint32_t>(x) |
(reinterpret_cast<ObjectPair>(y) << 32);
#endif
}
......@@ -6031,6 +6037,11 @@ static Object* Runtime_GetCFrames(Arguments args) {
Object* result = Runtime_CheckExecutionState(args);
if (result->IsFailure()) return result;
#if V8_HOST_ARCH_64_BIT
UNIMPLEMENTED();
return Heap::undefined_value();
#else
static const int kMaxCFramesSize = 200;
ScopedVector<OS::StackFrame> frames(kMaxCFramesSize);
int frames_count = OS::StackWalk(frames);
......@@ -6062,6 +6073,7 @@ static Object* Runtime_GetCFrames(Arguments args) {
frames_array->set(i, *frame_value);
}
return *Factory::NewJSArrayWithElements(frames_array);
#endif // V8_HOST_ARCH_64_BIT
}
......
......@@ -28,6 +28,8 @@
#ifndef V8_X64_ASSEMBLER_X64_INL_H_
#define V8_X64_ASSEMBLER_X64_INL_H_
#include "cpu.h"
namespace v8 { namespace internal {
Condition NegateCondition(Condition cc) {
......@@ -35,6 +37,24 @@ Condition NegateCondition(Condition cc) {
}
// The modes possibly affected by apply must be in kApplyMask.
void RelocInfo::apply(int delta) {
if (rmode_ == RUNTIME_ENTRY || IsCodeTarget(rmode_)) {
intptr_t* p = reinterpret_cast<intptr_t*>(pc_);
*p -= delta; // relocate entry
} else if (rmode_ == JS_RETURN && IsCallInstruction()) {
// Special handling of js_return when a break point is set (call
// instruction has been inserted).
intptr_t* p = reinterpret_cast<intptr_t*>(pc_ + 1);
*p -= delta; // relocate entry
} else if (IsInternalReference(rmode_)) {
// absolute code pointer inside code object moves with the code object.
intptr_t* p = reinterpret_cast<intptr_t*>(pc_);
*p += delta; // relocate entry
}
}
Address RelocInfo::target_address() {
ASSERT(IsCodeTarget(rmode_) || rmode_ == RUNTIME_ENTRY);
return Assembler::target_address_at(pc_);
......@@ -63,6 +83,71 @@ byte* Assembler::target_address_at(byte* location) {
return NULL;
}
Object* RelocInfo::target_object() {
ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return *reinterpret_cast<Object**>(pc_);
}
Object** RelocInfo::target_object_address() {
ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
return reinterpret_cast<Object**>(pc_);
}
Address* RelocInfo::target_reference_address() {
ASSERT(rmode_ == RelocInfo::EXTERNAL_REFERENCE);
return reinterpret_cast<Address*>(pc_);
}
void RelocInfo::set_target_object(Object* target) {
ASSERT(IsCodeTarget(rmode_) || rmode_ == EMBEDDED_OBJECT);
*reinterpret_cast<Object**>(pc_) = target;
}
bool RelocInfo::IsCallInstruction() {
UNIMPLEMENTED(); // IA32 code below.
return *pc_ == 0xE8;
}
Address RelocInfo::call_address() {
UNIMPLEMENTED(); // IA32 code below.
ASSERT(IsCallInstruction());
return Assembler::target_address_at(pc_ + 1);
}
void RelocInfo::set_call_address(Address target) {
UNIMPLEMENTED(); // IA32 code below.
ASSERT(IsCallInstruction());
Assembler::set_target_address_at(pc_ + 1, target);
}
Object* RelocInfo::call_object() {
UNIMPLEMENTED(); // IA32 code below.
ASSERT(IsCallInstruction());
return *call_object_address();
}
void RelocInfo::set_call_object(Object* target) {
UNIMPLEMENTED(); // IA32 code below.
ASSERT(IsCallInstruction());
*call_object_address() = target;
}
Object** RelocInfo::call_object_address() {
UNIMPLEMENTED(); // IA32 code below.
ASSERT(IsCallInstruction());
return reinterpret_cast<Object**>(pc_ + 1);
}
} } // namespace v8::internal
#endif // V8_X64_ASSEMBLER_X64_INL_H_
......@@ -473,7 +473,15 @@ class CodeGenerator: public AstVisitor {
void CheckStack();
struct InlineRuntimeLUT {
void (CodeGenerator::*method)(ZoneList<Expression*>*);
const char* name;
};
static InlineRuntimeLUT* FindInlineRuntimeLUT(Handle<String> name);
bool CheckForInlineRuntimeCall(CallRuntime* node);
static bool PatchInlineRuntimeEntry(Handle<String> name,
const InlineRuntimeLUT& new_entry,
InlineRuntimeLUT* old_entry);
Handle<JSFunction> BuildBoilerplate(FunctionLiteral* node);
void ProcessDeclarations(ZoneList<Declaration*>* declarations);
......@@ -604,6 +612,8 @@ class CodeGenerator: public AstVisitor {
// in a spilled state.
bool in_spilled_code_;
static InlineRuntimeLUT kInlineRuntimeLUT[];
friend class VirtualFrame;
friend class JumpTarget;
friend class Reference;
......
......@@ -25,3 +25,41 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// CPU specific code for x64 independent of OS goes here.
#include "v8.h"
#include "cpu.h"
#include "macro-assembler.h"
namespace v8 { namespace internal {
void CPU::Setup() {
CpuFeatures::Probe();
}
void CPU::FlushICache(void* start, size_t size) {
// No need to flush the instruction cache on Intel. On Intel instruction
// cache flushing is only necessary when multiple cores running the same
// code simultaneously. V8 (and JavaScript) is single threaded and when code
// is patched on an intel CPU the core performing the patching will have its
// own instruction cache updated automatically.
// If flushing of the instruction cache becomes necessary Windows has the
// API function FlushInstructionCache.
}
void CPU::DebugBreak() {
#ifdef _MSC_VER
// To avoid Visual Studio runtime support the following code can be used
// instead
// __asm { int 3 }
__debugbreak();
#else
asm("int $3");
#endif
}
} } // namespace v8::internal
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