001/*
002 * Copyright (c) 2012, 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.nodes;
024
025import java.util.*;
026
027import jdk.internal.jvmci.code.*;
028import jdk.internal.jvmci.meta.*;
029
030import com.oracle.graal.compiler.common.type.*;
031import com.oracle.graal.graph.*;
032import com.oracle.graal.nodeinfo.*;
033import com.oracle.graal.nodes.*;
034import com.oracle.graal.nodes.spi.*;
035
036/**
037 * Reserves a block of memory in the stack frame of a method. The block is reserved in the frame for
038 * the entire execution of the associated method.
039 */
040@NodeInfo
041public final class AllocaNode extends FixedWithNextNode implements LIRLowerable {
042
043    public static final NodeClass<AllocaNode> TYPE = NodeClass.create(AllocaNode.class);
044    /**
045     * The number of slots in block.
046     */
047    protected final int slots;
048
049    /**
050     * The indexes of the object pointer slots in the block. Each such object pointer slot must be
051     * initialized before any safepoint in the method otherwise the garbage collector will see
052     * garbage values when processing these slots.
053     */
054    protected final BitSet objects;
055
056    public AllocaNode(int slots, Kind wordKind, BitSet objects) {
057        super(TYPE, StampFactory.forKind(wordKind));
058        this.slots = slots;
059        this.objects = objects;
060    }
061
062    @Override
063    public void generate(NodeLIRBuilderTool gen) {
064        VirtualStackSlot array = gen.getLIRGeneratorTool().getResult().getFrameMapBuilder().allocateStackSlots(slots, objects, null);
065        Value result = gen.getLIRGeneratorTool().emitAddress(array);
066        gen.setResult(this, result);
067    }
068}