1/* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23package org.graalvm.compiler.bytecode; 24 25import jdk.vm.ci.meta.ConstantPool; 26import jdk.vm.ci.meta.ExceptionHandler; 27import jdk.vm.ci.meta.LineNumberTable; 28import jdk.vm.ci.meta.LocalVariableTable; 29import jdk.vm.ci.meta.ProfilingInfo; 30import jdk.vm.ci.meta.ResolvedJavaMethod; 31 32/** 33 * Direct access to the bytecode of a {@link ResolvedJavaMethod} that will reflect any 34 * instrumentation and rewriting performed on the {@link ResolvedJavaMethod}. 35 */ 36public class ResolvedJavaMethodBytecode implements Bytecode { 37 38 private final ResolvedJavaMethod method; 39 private final BytecodeProvider origin; 40 41 public ResolvedJavaMethodBytecode(ResolvedJavaMethod method) { 42 this(method, ResolvedJavaMethodBytecodeProvider.INSTANCE); 43 } 44 45 public ResolvedJavaMethodBytecode(ResolvedJavaMethod method, BytecodeProvider origin) { 46 this.method = method; 47 this.origin = origin; 48 } 49 50 @Override 51 public BytecodeProvider getOrigin() { 52 return origin; 53 } 54 55 @Override 56 public ResolvedJavaMethod getMethod() { 57 return method; 58 } 59 60 @Override 61 public byte[] getCode() { 62 return method.getCode(); 63 } 64 65 @Override 66 public int getCodeSize() { 67 return method.getCodeSize(); 68 } 69 70 @Override 71 public int getMaxStackSize() { 72 return method.getMaxStackSize(); 73 } 74 75 @Override 76 public int getMaxLocals() { 77 return method.getMaxLocals(); 78 } 79 80 @Override 81 public ConstantPool getConstantPool() { 82 return method.getConstantPool(); 83 } 84 85 @Override 86 public LineNumberTable getLineNumberTable() { 87 return method.getLineNumberTable(); 88 } 89 90 @Override 91 public LocalVariableTable getLocalVariableTable() { 92 return method.getLocalVariableTable(); 93 } 94 95 @Override 96 public ExceptionHandler[] getExceptionHandlers() { 97 return method.getExceptionHandlers(); 98 } 99 100 @Override 101 public StackTraceElement asStackTraceElement(int bci) { 102 return method.asStackTraceElement(bci); 103 } 104 105 @Override 106 public ProfilingInfo getProfilingInfo() { 107 return method.getProfilingInfo(); 108 } 109 110 @Override 111 public String toString() { 112 return getClass().getSimpleName() + method.format("<%h.%n(%p)>"); 113 } 114} 115