Fix timeout handling in the test harness.
1 /* vim: set ts=4 sw=4 tw=99 et:
3 * Copyright (C) 2012 David Anderson
5 * This file is part of JITCraft.
7 * JITCraft is free software: you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License as published by the Free
9 * Software Foundation, either version 3 of the License, or (at your option)
12 * Foobar is distributed in the hope that it will be useful, but WITHOUT ANY
13 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with
17 * JITCraft. If not, see http://www.gnu.org/licenses/.
26 #include "CompactBuffer.h"
27 #include "Structures.h"
32 OpInfo ke::OpcodeInfo[] =
34 #define OPDEF(name, text, length, uses, defs) \
35 {text, length, uses, defs},
36 #include "Opcodes.tbl"
41 Code::New(Zone *zone, Handle<ByteArray> bytecode, Handle<FixedArray> locals,
42 Handle<FixedArray> objects, Handle<FixedArray> strings, unsigned maxStackDepth,
43 Handle<ByteArray> safepoints, Handle<ByteArray> sourcemap)
45 Local<Code> code(zone, Code::cast(zone->allocate(MapKind_Code, sizeof(Code), Heap::Tenure_Old)));
49 code->bytecode_ = bytecode;
50 code->locals_ = locals;
51 code->objects_ = objects;
52 code->maxStackDepth_ = maxStackDepth;
54 code->safepoints_ = safepoints;
55 code->sourcemap_ = sourcemap;
56 code->lineNumber_ = 0;
57 code->strings_ = strings;
62 CompareSafepoints(const void *a, const void *b)
64 const unsigned *sa = reinterpret_cast<const unsigned *>(a);
65 const unsigned *sb = reinterpret_cast<const unsigned *>(b);
74 Code::safepointAt(unsigned pcOffset)
76 // Only specific opcodes may have safepoints. Asking for a safepoint at
77 // any other position indicates a failure to mark that position as a
78 // safepoint, which is a bug.
80 Opcode op = Opcode(*(start() + pcOffset));
81 assert(op == OP_CALL ||
85 op == OP_VARREF_LIFO ||
86 op == OP_ARGREF_LIFO ||
87 op == OP_SLOTREF_LIFO ||
89 op == OP_CALLNATIVE ||
96 size_t bytesPerSafepoint = BytesPerSafepoint(maxStackDepth());
97 assert(!(safepoints_->length() % bytesPerSafepoint));
99 size_t count = safepoints_->length() / bytesPerSafepoint;
101 void *result = bsearch(&pcOffset,
110 assert(*reinterpret_cast<unsigned *>(result) == pcOffset);
112 return Address(result) + sizeof(unsigned);
116 Code::pcToSource(unsigned pc)
118 assert(pc < bytecode_->length());
120 CompactBufferReader reader(sourcemap_->raw(), sourcemap_->raw() + sourcemap_->length());
125 while (!reader.done()) {
126 curPc += reader.readUint32();
130 line = reader.readUint32();
131 col = reader.readUint32();
134 return SourcePosition(lineNumber_ + line, col);
137 // All jumps must be the same length.
138 STATIC_ASSERT(OP_JT_LENGTH == OP_JUMP_LENGTH);
139 STATIC_ASSERT(OP_JF_LENGTH == OP_JUMP_LENGTH);
142 ke::Disassemble(Code *code, FILE *fp)
144 bytecode *pc = code->start();
146 Opcode op = Opcode(*pc);
148 fprintf(fp, "%-4d %s ", int(pc - code->start()), OpcodeInfo[op].name);
176 case OP_SLOTREF_LIFO:
217 fprintf(fp, "%d", READ_INT32(pc));
221 fprintf(fp, "%f", READ_FLOAT(pc));
227 fprintf(fp, "%u (%+d)", unsigned((pc + READ_INT32(pc)) - code->start()), READ_INT32(pc));
234 Heap::Tenure tenure = (Heap::Tenure)pc[1];
235 //ArrayMap *map = ArrayMap::cast(code->map(READ_UINT32(pc + 1)));
236 if (tenure == Heap::Tenure_Stack)
237 fprintf(fp, " ; lifo");
238 else if (tenure == Heap::Tenure_Old)
239 fprintf(fp, " ; pretenured");
240 else if (tenure == Heap::Tenure_Default)
241 fprintf(fp, " ; newborn");
247 Heap::Tenure tenure = (Heap::Tenure)pc[1];
248 StructMap *map = StructMap::cast(code->map(READ_UINT32(pc + 1)));
249 fprintf(fp, "%s", map->type()->name()->chars());
250 if (tenure == Heap::Tenure_Stack)
251 fprintf(fp, " ; lifo");
252 else if (tenure == Heap::Tenure_Old)
253 fprintf(fp, " ; pretenured");
254 else if (tenure == Heap::Tenure_Default)
255 fprintf(fp, " ; newborn");
270 fprintf(fp, "%u", READ_UINT32(pc));
275 unsigned argc = READ_UINT32(pc);
276 fprintf(fp, " ; %u args", argc);
282 int low = READ_TABLESWITCH_LOW(pc);
283 int high = READ_TABLESWITCH_HIGH(pc);
284 fprintf(fp, "%d, %d\n", low, high);
291 unsigned index = READ_UINT32(pc);
292 fprintf(fp, "%s", String::cast(code->strings()->at(index))->chars());
306 pc += OpcodeInfo[op].length;
307 assert(pc < code->start() + code->length());
310 fprintf(fp, "\nSafepoints:\n");
311 ByteArray *safepoints = code->safepoints();
313 size_t nsafepoints = safepoints->length() / Code::BytesPerSafepoint(code->maxStackDepth());
314 for (size_t i = 0; i < nsafepoints; i++) {
315 Address address = safepoints->raw() + Code::BytesPerSafepoint(code->maxStackDepth()) * i;
316 fprintf(fp, "%4d: ", *reinterpret_cast<unsigned *>(address));
317 unsigned char *bits = (unsigned char *)(address + sizeof(unsigned));
318 for (unsigned j = 0; j < code->maxStackDepth(); j++) {
319 if (bits[j / 8] & (1 << (j % 8)))
320 fprintf(fp, "%d ", j);