Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/jdi/LocationImpl.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;2627import com.sun.jdi.*;2829import java.util.*;3031public class LocationImpl extends MirrorImpl implements Location {32private final ReferenceTypeImpl declaringType;33private Method method;34private long methodRef;35private long codeIndex;36private LineInfo baseLineInfo = null;37private LineInfo otherLineInfo = null;3839LocationImpl(VirtualMachine vm,40Method method, long codeIndex) {41super(vm);4243this.method = method;44this.codeIndex = method.isNative()? -1 : codeIndex;45this.declaringType = (ReferenceTypeImpl)method.declaringType();46}4748/*49* This constructor allows lazy creation of the method mirror. This50* can be a performance savings if the method mirror does not yet51* exist.52*/53LocationImpl(VirtualMachine vm, ReferenceTypeImpl declaringType,54long methodRef, long codeIndex) {55super(vm);5657this.method = null;58this.codeIndex = codeIndex;59this.declaringType = declaringType;60this.methodRef = methodRef;61}6263public boolean equals(Object obj) {64if ((obj != null) && (obj instanceof Location)) {65Location other = (Location)obj;66return (method().equals(other.method())) &&67(codeIndex() == other.codeIndex()) &&68super.equals(obj);69} else {70return false;71}72}7374public int hashCode() {75/*76* TO DO: better hash code?77*/78return method().hashCode() + (int)codeIndex();79}8081public int compareTo(Location object) {82LocationImpl other = (LocationImpl)object;83int rc = method().compareTo(other.method());84if (rc == 0) {85long diff = codeIndex() - other.codeIndex();86if (diff < 0)87return -1;88else if (diff > 0)89return 1;90else91return 0;92}93return rc;94}9596public ReferenceType declaringType() {97return declaringType;98}99100public Method method() {101if (method == null) {102method = declaringType.getMethodMirror(methodRef);103if (method.isNative()) {104codeIndex = -1;105}106}107return method;108}109110public long codeIndex() {111method(); // be sure information is up-to-date112return codeIndex;113}114115LineInfo getBaseLineInfo(SDE.Stratum stratum) {116LineInfo lineInfo;117118/* check if there is cached info to use */119if (baseLineInfo != null) {120return baseLineInfo;121}122123/* compute the line info */124MethodImpl methodImpl = (MethodImpl)method();125lineInfo = methodImpl.codeIndexToLineInfo(stratum,126codeIndex());127128/* cache it */129addBaseLineInfo(lineInfo);130131return lineInfo;132}133134LineInfo getLineInfo(SDE.Stratum stratum) {135LineInfo lineInfo;136137/* base stratum is done slighly differently */138if (stratum.isJava()) {139return getBaseLineInfo(stratum);140}141142/* check if there is cached info to use */143lineInfo = otherLineInfo; // copy because of concurrency144if (lineInfo != null &&145stratum.id().equals(lineInfo.liStratum())) {146return lineInfo;147}148149int baseLineNumber = lineNumber(SDE.BASE_STRATUM_NAME);150SDE.LineStratum lineStratum =151stratum.lineStratum(declaringType, baseLineNumber);152153if (lineStratum != null && lineStratum.lineNumber() != -1) {154lineInfo = new StratumLineInfo(stratum.id(),155lineStratum.lineNumber(),156lineStratum.sourceName(),157lineStratum.sourcePath());158} else {159/* find best match */160MethodImpl methodImpl = (MethodImpl)method();161lineInfo = methodImpl.codeIndexToLineInfo(stratum,162codeIndex());163}164165/* cache it */166addStratumLineInfo(lineInfo);167168return lineInfo;169}170171void addStratumLineInfo(LineInfo lineInfo) {172otherLineInfo = lineInfo;173}174175void addBaseLineInfo(LineInfo lineInfo) {176baseLineInfo = lineInfo;177}178179public String sourceName() throws AbsentInformationException {180return sourceName(vm.getDefaultStratum());181}182183public String sourceName(String stratumID)184throws AbsentInformationException {185return sourceName(declaringType.stratum(stratumID));186}187188String sourceName(SDE.Stratum stratum)189throws AbsentInformationException {190return getLineInfo(stratum).liSourceName();191}192193public String sourcePath() throws AbsentInformationException {194return sourcePath(vm.getDefaultStratum());195}196197public String sourcePath(String stratumID)198throws AbsentInformationException {199return sourcePath(declaringType.stratum(stratumID));200}201202String sourcePath(SDE.Stratum stratum)203throws AbsentInformationException {204return getLineInfo(stratum).liSourcePath();205}206207public int lineNumber() {208return lineNumber(vm.getDefaultStratum());209}210211public int lineNumber(String stratumID) {212return lineNumber(declaringType.stratum(stratumID));213}214215int lineNumber(SDE.Stratum stratum) {216return getLineInfo(stratum).liLineNumber();217}218219public String toString() {220if (lineNumber() == -1) {221return method().toString() + "+" + codeIndex();222} else {223return declaringType().name() + ":" + lineNumber();224}225}226}227228229