Stop using ccache on OS X.
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/.
30 Stack::Stack(Zone *zone)
45 buffer_ = (char *)malloc(STACK_SIZE);
49 top_.sp = reinterpret_cast<LocalSlot *>(buffer_);
52 end_ = buffer_ + STACK_SIZE;
56 InvokeArgs::~InvokeArgs()
58 stack_->popInvokeFrame(*this);
61 NativeArgs::~NativeArgs()
63 stack_->popNativeFrame(*this);
67 SizeForCodeFrame(Code *code)
69 return sizeof(Frame) + sizeof(LocalSlot) * (code->nlocals() + code->maxStackDepth());
73 Stack::pushInvokeFrame(Handle<Function> fun, InvokeArgs &args)
75 size_t nbytes = SizeForCodeFrame(fun->code()) +
76 sizeof(LocalSlot) * fun->nargs();
77 if (reinterpret_cast<char *>(top_.sp) + nbytes >= end_) {
82 memset(top_.sp, 0, sizeof(LocalSlot) * fun->nargs());
84 args.nargs_ = fun->nargs();
86 top_.sp += fun->nargs();
88 Frame *frame = reinterpret_cast<Frame *>(top_.sp);
89 new (frame) Frame(top_.fp, top_.pc, fun, fun->code(), zone_->heap().lifoPosition());
91 top_.pc = frame->code()->start();
92 top_.sp = frame->stackBase();
99 Stack::pushModuleFrame(Handle<Module> module, InvokeArgs &args)
101 size_t nbytes = SizeForCodeFrame(module->code());
102 if (reinterpret_cast<char *>(top_.sp) + nbytes >= end_) {
107 args.args_ = top_.sp;
111 Frame *frame = reinterpret_cast<Frame *>(top_.sp);
112 new (frame) Frame(top_.fp, top_.pc, NULL, module->code(), zone_->heap().lifoPosition());
114 top_.pc = frame->code()->start();
115 top_.sp = frame->stackBase();
122 Stack::pushNativeFrame(Handle<Native> native, NativeArgs &args, unsigned argc)
124 size_t nbytes = sizeof(intptr_t) * argc + sizeof(Frame);
125 if (reinterpret_cast<char *>(top_.sp) + nbytes >= end_) {
130 memset(top_.sp, 0, sizeof(intptr_t) * argc);
131 args.argsBase_ = top_.sp;
133 top_.sp = reinterpret_cast<LocalSlot *>(reinterpret_cast<intptr_t *>(top_.sp) + argc);
135 Frame *frame = reinterpret_cast<Frame *>(top_.sp);
136 new (frame) Frame(top_.fp, top_.pc, native, zone_->heap().lifoPosition());
139 top_.sp = reinterpret_cast<LocalSlot *>(frame + 1);
146 Stack::pushInlineFrame(Handle<Function> fun)
148 Code *code = fun->code();
149 size_t nbytes = SizeForCodeFrame(code);
150 if (reinterpret_cast<char *>(top_.sp) + nbytes >= end_) {
151 zone_->reportError(Message_TooMuchRecursion);
155 Frame *frame = reinterpret_cast<Frame *>(top_.sp);
156 new (frame) Frame(top_.fp, top_.pc, fun, code, zone_->heap().lifoPosition());
157 memset(frame->locals(), 0, sizeof(LocalSlot) * code->nlocals());
159 top_.pc = frame->code()->start();
160 top_.sp = frame->stackBase();
168 Stack::popInlineFrame()
170 zone_->heap().unwindLifo(top_.fp->lifoPosition());
172 Frame *prev = top_.fp->prev();
173 Function *fun = top_.fp->fun();
175 top_.pc = top_.fp->prevpc();
176 top_.sp = reinterpret_cast<LocalSlot *>(top_.fp) - fun->nargs();
182 Stack::popInvokeFrame(InvokeArgs &args)
184 zone_->heap().unwindLifo(top_.fp->lifoPosition());
186 top_.pc = top_.fp->prevpc();
187 top_.sp = args.args_;
188 top_.fp = top_.fp->prev();
192 Stack::popNativeFrame(NativeArgs &args)
194 zone_->heap().unwindLifo(top_.fp->lifoPosition());
196 top_.pc = top_.fp->prevpc();
197 top_.sp = args.argsBase_;
198 top_.fp = top_.fp->prev();
202 Frame::accept(VirtualObjectVisitor *visitor)
204 visitor->visit(reinterpret_cast<Object **>(&callee_));
205 visitor->visit(reinterpret_cast<Object **>(&code_));
209 TraceFunctionFrame(VirtualObjectVisitor *visitor, Frame *fp, LocalSlot *sp, bytecode *pc)
211 Code *code = fp->code();
212 LocalSlot *slots = fp->locals();
214 // Trace local variables.
215 for (unsigned i = 0; i < code->nlocals(); i++) {
216 Type *type = code->localType(i);
217 if (type->isTraceable())
218 visitor->visit(&slots[i].obj);
221 // Trace arguments, if a function call. Note that this means we usually
222 // mark arguments twice, once on the caller side and once on the callee.
223 // This makes it easier to deal with invoke frames which have no caller.
224 if (Function *fun = fp->maybeFun()) {
225 for (unsigned i = 0; i < fun->nargs(); i++) {
226 Type *type = fun->argType(i);
227 if (type->isTraceable())
228 visitor->visit(&fp->arg(i).obj);
232 // Finally, trace stack slots. Not every gc-point in the bytecode will
233 // have a safepoint; since they are actually uncommon, we don't emit
234 // them unless at least one stack slot would be marked.
235 if (uint8 *safepoint = code->safepointAt(code->pcToOffset(pc))) {
236 LocalSlot *base = fp->stackBase();
237 unsigned stackDepth = unsigned(sp - fp->stackBase());
238 assert(stackDepth <= code->maxStackDepth());
240 for (unsigned i = 0; i < stackDepth; i++) {
241 if (safepoint[i / 8] & (1 << (i % 8)))
242 visitor->visit(&base[i].obj);
248 Stack::accept(VirtualObjectVisitor *visitor)
250 LocalSlot *sp = top_.sp;
251 bytecode *pc = top_.pc;
253 for (Frame *frame = top_.fp; frame; frame = frame->prev()) {
254 if (!frame->isNative())
255 TraceFunctionFrame(visitor, frame, sp, pc);
256 frame->accept(visitor);
258 sp = reinterpret_cast<LocalSlot *>(frame);
259 pc = frame->prevpc();
264 Stack::isInCallStack(Handle<Module> module)
266 for (Frame *frame = top_.fp; frame; frame = frame->prev()) {
267 if (frame->code()->module() == module)
273 StackIter::StackIter(Zone *zone)
274 : pc_(zone->stack().top()->pc),
275 fp_(zone->stack().top()->fp)
280 StackIter::done() const
286 StackIter::function() const
289 return fp_->native()->name()->chars();
290 if (Function *fun = fp_->maybeFun())
291 return fun->name()->chars();
296 StackIter::lineNumber() const
300 if (fp_->maybeFun()) {
301 unsigned offs = fp_->code()->pcToOffset(pc_);
302 return fp_->code()->pcToSource(offs).line;
304 return fp_->code()->lineNumber();
308 StackIter::source() const
312 return fp_->code()->module()->file()
313 ? fp_->code()->module()->file()->chars()