1 /* 2 * Copyright (c) 2005, 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 package jdk.test.lib.jittester.functions; 25 26 import java.util.ArrayList; 27 import java.util.Arrays; 28 29 import jdk.test.lib.jittester.Symbol; 30 import jdk.test.lib.jittester.Type; 31 import jdk.test.lib.jittester.VariableInfo; 32 import jdk.test.lib.jittester.types.TypeKlass; 33 34 public class FunctionInfo extends Symbol { 35 public ArrayList<VariableInfo> argTypes; 36 public long complexity = 0; 37 public static final int ABSTRACT = 0x40; 38 public static final int NONRECURSIVE = 0x80; 39 public static final int SYNCHRONIZED = 0x100; 40 41 public FunctionInfo() { 42 } 43 44 public FunctionInfo(String name, TypeKlass ownerClass, Type returnType, 45 long complexity, int flags, VariableInfo... args) { 46 super(name, ownerClass, returnType, flags); 47 argTypes = new ArrayList<>(); 48 argTypes.addAll(Arrays.asList(args)); 49 this.complexity = complexity; 50 } 51 52 public FunctionInfo(String name, TypeKlass ownerClass, Type returnType, 53 long complexity, int flags, ArrayList<VariableInfo> args) { 54 super(name, ownerClass, returnType, flags); 55 argTypes = args; 56 this.complexity = complexity; 57 } 58 59 public FunctionInfo(FunctionInfo value) { 60 super(value); 61 argTypes = new ArrayList<>(); 62 for (VariableInfo i : value.argTypes) { 63 argTypes.add(new VariableInfo(i)); 64 } 65 complexity = value.complexity; 66 } 67 68 public boolean isSynchronized() { 69 return (flags & SYNCHRONIZED) > 0; 70 } 71 72 @Override 73 protected Symbol copy() { 74 return this; 75 } 76 77 @Override 78 public Symbol deepCopy() { 79 return new FunctionInfo(this); 80 } 81 82 @Override 83 public boolean equals(Object o) { 84 if (this == o) { 85 return true; 86 } 87 if (o == null || !(o instanceof FunctionInfo)) { 88 return false; 89 } 90 91 try { 92 FunctionInfo f = (FunctionInfo) o; 93 return owner.equals(f.owner) && hasEqualSignature(o); 94 } catch (Exception e) { 95 } 96 return false; 97 } 98 99 protected boolean hasEqualSignature(Object o) { 100 try { 101 FunctionInfo f = (FunctionInfo) o; 102 if (name.equals(f.name)) { 103 int i = (flags & STATIC) > 0 ? 0 : 1; 104 int j = (f.flags & STATIC) > 0 ? 0 : 1; 105 106 if (argTypes.size() - i == f.argTypes.size() - j) { 107 while (i < argTypes.size() && j < f.argTypes.size()) { 108 if (!argTypes.get(i++).type.equals(f.argTypes.get(j++).type)) { 109 return false; 110 } 111 } 112 return true; 113 } 114 } 115 } catch (Exception e) { 116 } 117 return false; 118 } 119 120 public boolean isConstructor() { 121 return name.equals(owner.getName()); 122 } 123 124 @Override 125 public int hashCode() { 126 return name.hashCode(); 127 } 128 129 @Override 130 public boolean isStatic() { 131 return (flags & STATIC) > 0; 132 } 133 }