001/*
002 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.hotspot;
024
025import static jdk.internal.jvmci.code.BytecodeFrame.*;
026
027import com.oracle.graal.compiler.gen.*;
028import com.oracle.graal.nodes.*;
029import com.oracle.graal.nodes.spi.*;
030
031import jdk.internal.jvmci.code.*;
032import jdk.internal.jvmci.common.*;
033import jdk.internal.jvmci.meta.*;
034
035/**
036 * Extends {@link DebugInfoBuilder} to allocate the extra debug information required for locks.
037 */
038public class HotSpotDebugInfoBuilder extends DebugInfoBuilder {
039
040    private final HotSpotLockStack lockStack;
041
042    public HotSpotDebugInfoBuilder(NodeValueMap nodeValueMap, HotSpotLockStack lockStack) {
043        super(nodeValueMap);
044        this.lockStack = lockStack;
045    }
046
047    public HotSpotLockStack lockStack() {
048        return lockStack;
049    }
050
051    @Override
052    protected Value computeLockValue(FrameState state, int lockIndex) {
053        int lockDepth = lockIndex;
054        if (state.outerFrameState() != null) {
055            lockDepth += state.outerFrameState().nestedLockDepth();
056        }
057        StackSlotValue slot = lockStack.makeLockSlot(lockDepth);
058        ValueNode lock = state.lockAt(lockIndex);
059        Value object = toValue(lock);
060        boolean eliminated = object instanceof VirtualObject || state.monitorIdAt(lockIndex) == null;
061        assert state.monitorIdAt(lockIndex) == null || state.monitorIdAt(lockIndex).getLockDepth() == lockDepth;
062        return new StackLockValue(object, slot, eliminated);
063    }
064
065    @Override
066    protected BytecodeFrame computeFrameForState(FrameState state) {
067        if (isPlaceholderBci(state.bci) && state.bci != BytecodeFrame.BEFORE_BCI) {
068            // This is really a hard error since an incorrect state could crash hotspot
069            throw JVMCIError.shouldNotReachHere("Invalid state " + BytecodeFrame.getPlaceholderBciName(state.bci) + " " + state);
070        }
071        return super.computeFrameForState(state);
072    }
073}