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  */
  23 
  24 
  25 package org.graalvm.compiler.bytecode;
  26 
  27 import jdk.vm.ci.meta.ConstantPool;
  28 import jdk.vm.ci.meta.ExceptionHandler;
  29 import jdk.vm.ci.meta.LineNumberTable;
  30 import jdk.vm.ci.meta.LocalVariableTable;
  31 import jdk.vm.ci.meta.ProfilingInfo;
  32 import jdk.vm.ci.meta.ResolvedJavaMethod;
  33 
  34 /**
  35  * Direct access to the bytecode of a {@link ResolvedJavaMethod} that will reflect any
  36  * instrumentation and rewriting performed on the {@link ResolvedJavaMethod}.
  37  */
  38 public class ResolvedJavaMethodBytecode implements Bytecode {
  39 
  40     private final ResolvedJavaMethod method;
  41     private final BytecodeProvider origin;
  42 
  43     public ResolvedJavaMethodBytecode(ResolvedJavaMethod method) {
  44         this(method, ResolvedJavaMethodBytecodeProvider.INSTANCE);
  45     }
  46 
  47     public ResolvedJavaMethodBytecode(ResolvedJavaMethod method, BytecodeProvider origin) {
  48         this.method = method;
  49         this.origin = origin;
  50     }
  51 
  52     @Override
  53     public BytecodeProvider getOrigin() {
  54         return origin;
  55     }
  56 
  57     @Override
  58     public ResolvedJavaMethod getMethod() {
  59         return method;
  60     }
  61 
  62     @Override
  63     public byte[] getCode() {
  64         return method.getCode();
  65     }
  66 
  67     @Override
  68     public int getCodeSize() {
  69         return method.getCodeSize();
  70     }
  71 
  72     @Override
  73     public int getMaxStackSize() {
  74         return method.getMaxStackSize();
  75     }
  76 
  77     @Override
  78     public int getMaxLocals() {
  79         return method.getMaxLocals();
  80     }
  81 
  82     @Override
  83     public ConstantPool getConstantPool() {
  84         return method.getConstantPool();
  85     }
  86 
  87     @Override
  88     public LineNumberTable getLineNumberTable() {
  89         return method.getLineNumberTable();
  90     }
  91 
  92     @Override
  93     public LocalVariableTable getLocalVariableTable() {
  94         return method.getLocalVariableTable();
  95     }
  96 
  97     @Override
  98     public ExceptionHandler[] getExceptionHandlers() {
  99         return method.getExceptionHandlers();
 100     }
 101 
 102     @Override
 103     public StackTraceElement asStackTraceElement(int bci) {
 104         return method.asStackTraceElement(bci);
 105     }
 106 
 107     @Override
 108     public ProfilingInfo getProfilingInfo() {
 109         return method.getProfilingInfo();
 110     }
 111 
 112     @Override
 113     public String toString() {
 114         return getClass().getSimpleName() + method.format("<%h.%n(%p)>");
 115     }
 116 }