001/* 002 * Copyright (c) 2012, 2015, 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 jdk.internal.jvmci.code.*; 026import jdk.internal.jvmci.meta.*; 027import static com.oracle.graal.hotspot.HotSpotBackend.*; 028import static com.oracle.graal.hotspot.nodes.CStringNode.*; 029 030import com.oracle.graal.compiler.common.spi.*; 031import com.oracle.graal.compiler.common.type.*; 032import com.oracle.graal.graph.*; 033import com.oracle.graal.nodeinfo.*; 034import com.oracle.graal.nodes.*; 035import com.oracle.graal.nodes.spi.*; 036import com.oracle.graal.replacements.*; 037 038/** 039 * Causes the VM to exit with a description of the current Java location and an optional 040 * {@linkplain Log#printf(String, long) formatted} error message specified. 041 */ 042@NodeInfo 043public final class VMErrorNode extends DeoptimizingStubCall implements LIRLowerable { 044 045 public static final NodeClass<VMErrorNode> TYPE = NodeClass.create(VMErrorNode.class); 046 protected final String format; 047 @Input ValueNode value; 048 049 public VMErrorNode(String format, ValueNode value) { 050 super(TYPE, StampFactory.forVoid()); 051 this.format = format; 052 this.value = value; 053 } 054 055 @Override 056 public void generate(NodeLIRBuilderTool gen) { 057 String whereString; 058 if (stateBefore() != null) { 059 String nl = CodeUtil.NEW_LINE; 060 StringBuilder sb = new StringBuilder("in compiled code associated with frame state:"); 061 FrameState fs = stateBefore(); 062 while (fs != null) { 063 MetaUtil.appendLocation(sb.append(nl).append("\t"), fs.method(), fs.bci); 064 fs = fs.outerFrameState(); 065 } 066 whereString = sb.toString(); 067 } else { 068 ResolvedJavaMethod method = graph().method(); 069 whereString = "in compiled code for " + (method == null ? graph().toString() : method.format("%H.%n(%p)")); 070 } 071 Value whereArg = emitCString(gen, whereString); 072 Value formatArg = emitCString(gen, format); 073 074 ForeignCallLinkage linkage = gen.getLIRGeneratorTool().getForeignCalls().lookupForeignCall(VM_ERROR); 075 gen.getLIRGeneratorTool().emitForeignCall(linkage, null, whereArg, formatArg, gen.operand(value)); 076 } 077 078 @NodeIntrinsic 079 public static native void vmError(@ConstantNodeParameter String format, long value); 080}