1 /*
   2  * Copyright (c) 2009, 2015, 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 com.sun.hotspot.tools.compiler;
  26 
  27 import java.util.Arrays;
  28 
  29 import static com.sun.hotspot.tools.compiler.Constants.*;
  30 
  31 /**
  32  * Representation of a Java method in a compilation log.
  33  */
  34 public class Method {
  35 
  36     /**
  37      * The name of the class holding the method.
  38      */
  39     private String holder;
  40     
  41     /**
  42      * The method's name.
  43      */
  44     private String name;
  45     
  46     /**
  47      * The return type of the method, as a fully qualified (source-level) class
  48      * or primitive type name.
  49      */
  50     private String returnType;
  51     
  52     /**
  53      * The method's signature, in internal form.
  54      */
  55     private String signature;
  56     
  57     /**
  58      * The length of the method's byte code.
  59      */
  60     private String bytes;
  61     
  62     /**
  63      * The number of times this method was invoked in the interpreter.
  64      */
  65     private String iicount;
  66     
  67     /**
  68      * The method's flags, in the form of a {@code String} representing the
  69      * {@code int} encoding them.
  70      */
  71     private String flags;
  72 
  73     /**
  74      * Decode the {@link flags} numerical string to a format for console
  75      * output. The result does not honour all possible flags but includes
  76      * information about OSR compilation.
  77      * 
  78      * @param osr_bci the byte code index at which an OSR compilation takes
  79      * place, or -1 if the compilation is not an OSR one.
  80      */
  81     String decodeFlags(int osr_bci) {
  82         int f = Integer.parseInt(getFlags());
  83         char[] c = new char[4];
  84         Arrays.fill(c, ' ');
  85         if (osr_bci >= 0) {
  86             c[0] = '%';
  87         }
  88         if ((f & JVM_ACC_SYNCHRONIZED) != 0) {
  89             c[1] = 's';
  90         }
  91         return new String(c);
  92     }
  93 
  94     /**
  95      * Format this method for console output.
  96      * 
  97      * @param osr_bci the byte code index at which OSR takes place, or -1 if no
  98      * OSR compilation is going on.
  99      */
 100     String format(int osr_bci) {
 101         if (osr_bci >= 0) {
 102             return getHolder() + "::" + getName() + " @ " + osr_bci + " (" + getBytes() + " bytes)";
 103         } else {
 104             return getHolder() + "::" + getName() + " (" + getBytes() + " bytes)";
 105         }
 106     }
 107 
 108     @Override
 109     public String toString() {
 110         return getHolder() + "::" + getName() + " (" + getBytes() + " bytes)";
 111     }
 112     
 113     public String getFullName() {
 114         return getHolder().replace('/', '.') + "." + getName() + signature;
 115     }
 116 
 117     public String getHolder() {
 118         return holder;
 119     }
 120 
 121     public void setHolder(String holder) {
 122         this.holder = holder;
 123     }
 124 
 125     public String getName() {
 126         return name;
 127     }
 128 
 129     public void setName(String name) {
 130         this.name = name;
 131     }
 132 
 133     public String getReturnType() {
 134         return returnType;
 135     }
 136 
 137     public void setReturnType(String returnType) {
 138         this.returnType = returnType;
 139     }
 140 
 141     public String getSignature() {
 142         return signature;
 143     }
 144 
 145     public void setSignature(String signature) {
 146         this.signature = signature.replace('/', '.');
 147     }
 148     
 149     public String getArguments() {
 150         return signature.substring(0, signature.indexOf(')') + 1);
 151     }
 152 
 153     public String getBytes() {
 154         return bytes;
 155     }
 156 
 157     public void setBytes(String bytes) {
 158         this.bytes = bytes;
 159     }
 160 
 161     public String getIICount() {
 162         return iicount;
 163     }
 164 
 165     public void setIICount(String iicount) {
 166         this.iicount = iicount;
 167     }
 168 
 169     public String getFlags() {
 170         return flags;
 171     }
 172 
 173     public void setFlags(String flags) {
 174         this.flags = flags;
 175     }
 176 
 177     @Override
 178     public boolean equals(Object o) {
 179         if (o instanceof Method) {
 180             Method other = (Method) o;
 181             return holder.equals(other.holder) && name.equals(other.name) && signature.equals(other.signature);
 182         }
 183         return false;
 184     }
 185     
 186     public int hashCode() {
 187         return holder.hashCode() ^ name.hashCode();
 188     }
 189 }