Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/jdi/LocalVariableImpl.java
38920 views
/*1* Copyright (c) 1998, 2004, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdi;26import com.sun.jdi.*;2728public class LocalVariableImpl extends MirrorImpl29implements LocalVariable, ValueContainer30{31private final Method method;32private final int slot;33private final Location scopeStart;34private final Location scopeEnd;35private final String name;36private final String signature;37private String genericSignature = null;3839LocalVariableImpl(VirtualMachine vm, Method method,40int slot, Location scopeStart, Location scopeEnd,41String name, String signature,42String genericSignature) {43super(vm);44this.method = method;45this.slot = slot;46this.scopeStart = scopeStart;47this.scopeEnd = scopeEnd;48this.name = name;49this.signature = signature;50if (genericSignature != null && genericSignature.length() > 0) {51this.genericSignature = genericSignature;52} else {53// The Spec says to return null for non-generic types54this.genericSignature = null;55}56}5758public boolean equals(Object obj) {59if ((obj != null) && (obj instanceof LocalVariableImpl)) {60LocalVariableImpl other = (LocalVariableImpl)obj;61return ((slot() == other.slot()) &&62(scopeStart != null) &&63(scopeStart.equals(other.scopeStart)) &&64(super.equals(obj)));65} else {66return false;67}68}6970public int hashCode() {71/*72* TO DO: Better hash code73*/74return ((scopeStart.hashCode() << 4) + slot());75}7677public int compareTo(LocalVariable object) {78LocalVariableImpl other = (LocalVariableImpl)object;7980int rc = scopeStart.compareTo(other.scopeStart);81if (rc == 0) {82rc = slot() - other.slot();83}84return rc;85}8687public String name() {88return name;89}9091/**92* @return a text representation of the declared type93* of this variable.94*/95public String typeName() {96JNITypeParser parser = new JNITypeParser(signature);97return parser.typeName();98}99100public Type type() throws ClassNotLoadedException {101return findType(signature());102}103104public Type findType(String signature) throws ClassNotLoadedException {105ReferenceTypeImpl enclosing = (ReferenceTypeImpl)method.declaringType();106return enclosing.findType(signature);107}108109public String signature() {110return signature;111}112113public String genericSignature() {114return genericSignature;115}116117public boolean isVisible(StackFrame frame) {118validateMirror(frame);119Method frameMethod = frame.location().method();120121if (!frameMethod.equals(method)) {122throw new IllegalArgumentException(123"frame method different than variable's method");124}125126// this is here to cover the possibility that we will127// allow LocalVariables for native methods. If we do128// so we will have to re-examinine this.129if (frameMethod.isNative()) {130return false;131}132133return ((scopeStart.compareTo(frame.location()) <= 0)134&& (scopeEnd.compareTo(frame.location()) >= 0));135}136137public boolean isArgument() {138try {139MethodImpl method = (MethodImpl)scopeStart.method();140return (slot < method.argSlotCount());141} catch (AbsentInformationException e) {142// If this variable object exists, there shouldn't be absent info143throw new InternalException();144}145}146147int slot() {148return slot;149}150151/*152* Compilers/VMs can have byte code ranges for variables of the153* same names that overlap. This is because the byte code ranges154* aren't necessarily scopes; they may have more to do with the155* lifetime of the variable's slot, depending on implementation.156*157* This method determines whether this variable hides an158* identically named variable; ie, their byte code ranges overlap159* this one starts after the given one. If it returns true this160* variable should be preferred when looking for a single variable161* with its name when both variables are visible.162*/163boolean hides(LocalVariable other) {164LocalVariableImpl otherImpl = (LocalVariableImpl)other;165if (!method.equals(otherImpl.method) ||166!name.equals(otherImpl.name)) {167return false;168} else {169return (scopeStart.compareTo(otherImpl.scopeStart) > 0);170}171}172173public String toString() {174return name() + " in " + method.toString() +175"@" + scopeStart.toString();176}177}178179180