Path: blob/master/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/debugger/Address.java
41161 views
/*1* Copyright (c) 2000, 2008, 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.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324package sun.jvm.hotspot.debugger;2526/** <P> This is the bottom-most interface which abstracts address27access for both debugging and introspection. In the situation of28debugging a target VM, these routines can throw the specified29RuntimeExceptions to indicate failure and allow recovery of the30debugging system. If these are used for introspecting the current31VM and implementing functionality in it, however, it is expected32that these kinds of failures will not occur and, in fact, a crash33will occur if the situation arises where they would have been34thrown. </P>3536<P> Addresses are immutable. Further, it was decided not to expose37the representation of the Address (and provide a corresponding38factory method from, for example, long to Address). Unfortunately,39because of the existence of C and "reuse" of low bits of pointers,40it is occasionally necessary to perform logical operations like41masking off the low bits of an "address". While these operations42could be used to generate arbitrary Address objects, allowing this43is not the intent of providing these operations. </P>4445<P> This interface is able to fetch all Java primitive types,46addresses, oops, and C integers of arbitrary size (see @see47sun.jvm.hotspot.types.CIntegerType for further discussion). Note48that the result of the latter is restricted to fitting into a4964-bit value and the high-order bytes will be silently discarded50if too many bytes are requested. </P>5152<P> Implementations may have restrictions, for example that the53Java-related routines may not be called until a certain point in54the bootstrapping process once the sizes of the Java primitive55types are known. (The current implementation has that property.)56</P>5758<P> A note of warning: in C addresses, when represented as59integers, are usually represented with unsigned types.60Unfortunately, there are no unsigned primitive types in Java, so61care will have to be taken in the implementation of this interface62if using longs as the representation for 64-bit correctness. This63is not so simple for the comparison operators. </P> */6465public interface Address {6667/** This is stated explicitly here because it is important for68implementations to understand that equals() and hashCode() must69absolutely, positively work properly -- i.e., two Address70objects representing the same address are both equal (via71equals()) and have the same hash code. */72public boolean equals(Object arg);7374/** This is stated explicitly here because it is important for75implementations to understand that equals() and hashCode() must76absolutely, positively work properly -- i.e., two Address77objects representing the same address are both equal (via78equals()) and have the same hash code. */79public int hashCode();8081//82// C/C++-related routines83//8485public long getCIntegerAt (long offset, long numBytes, boolean isUnsigned)86throws UnmappedAddressException, UnalignedAddressException;87/** This returns null if the address at the given offset is NULL. */88public Address getAddressAt (long offset) throws UnmappedAddressException, UnalignedAddressException;89/** Returns the decoded address at the given offset */90public Address getCompOopAddressAt (long offset) throws UnmappedAddressException, UnalignedAddressException;91public Address getCompKlassAddressAt (long offset) throws UnmappedAddressException, UnalignedAddressException;9293//94// Java-related routines95//9697public boolean getJBooleanAt (long offset) throws UnmappedAddressException, UnalignedAddressException;98public byte getJByteAt (long offset) throws UnmappedAddressException, UnalignedAddressException;99public char getJCharAt (long offset) throws UnmappedAddressException, UnalignedAddressException;100public double getJDoubleAt (long offset) throws UnmappedAddressException, UnalignedAddressException;101public float getJFloatAt (long offset) throws UnmappedAddressException, UnalignedAddressException;102public int getJIntAt (long offset) throws UnmappedAddressException, UnalignedAddressException;103public long getJLongAt (long offset) throws UnmappedAddressException, UnalignedAddressException;104public short getJShortAt (long offset) throws UnmappedAddressException, UnalignedAddressException;105/** This returns null if the address at the given offset is NULL. */106public OopHandle getOopHandleAt (long offset)107throws UnmappedAddressException, UnalignedAddressException, NotInHeapException;108public OopHandle getCompOopHandleAt (long offset)109throws UnmappedAddressException, UnalignedAddressException, NotInHeapException;110111//112// C/C++-related mutators. These throw UnmappedAddressException if113// the target is read-only (for example, a core file rather than an114// active process), if the target address is unmapped, or if it is115// read-only. The implementation may supply extra detail messages.116//117118/** Sets a C integer numBytes in size at the specified offset. Note119that there is no "unsigned" flag for the accessor since the120value will not be sign-extended; the number of bytes are simply121copied from the value into the target address space. */122public void setCIntegerAt(long offset, long numBytes, long value);123124/** Sets an Address at the specified location. */125public void setAddressAt(long offset, Address value);126127//128// Java-related mutators -- see above.129//130131public void setJBooleanAt (long offset, boolean value)132throws UnmappedAddressException, UnalignedAddressException;133public void setJByteAt (long offset, byte value)134throws UnmappedAddressException, UnalignedAddressException;135public void setJCharAt (long offset, char value)136throws UnmappedAddressException, UnalignedAddressException;137public void setJDoubleAt (long offset, double value)138throws UnmappedAddressException, UnalignedAddressException;139public void setJFloatAt (long offset, float value)140throws UnmappedAddressException, UnalignedAddressException;141public void setJIntAt (long offset, int value)142throws UnmappedAddressException, UnalignedAddressException;143public void setJLongAt (long offset, long value)144throws UnmappedAddressException, UnalignedAddressException;145public void setJShortAt (long offset, short value)146throws UnmappedAddressException, UnalignedAddressException;147public void setOopHandleAt (long offset, OopHandle value)148throws UnmappedAddressException, UnalignedAddressException;149150//151// Arithmetic operations -- necessary evil.152//153154/** This throws an UnsupportedOperationException if this address happens155to actually be an OopHandle, because interior object pointers156are not allowed. Negative offsets are allowed and handle the157subtraction case. */158public Address addOffsetTo (long offset) throws UnsupportedOperationException;159160/** This method had to be added in order to support heap iteration161in the debugging system, and is effectively the dangerous162operation of allowing interior object pointers. For this reason163it was kept as a separate API and its use is forbidden in the164non-debugging (i.e., reflective system) case. It is strongly165recommended that this not be called by clients: it is currently166wrapped up in the Space's iteration mechanism. */167public OopHandle addOffsetToAsOopHandle(long offset) throws UnsupportedOperationException;168169/** Performs the subtraction "this - arg", returning the resulting170offset in bytes. Note that this must handle a null argument171properly, and can be used to convert an Address into a long for172further manipulation, but that the reverse conversion is not173possible. (FIXME: any signed/unsigned issues? Should this work174for OopHandles?) */175public long minus(Address arg);176177/** Performs unsigned comparison "this < arg".178(FIXME: should this work for OopHandles?) */179public boolean lessThan (Address arg);180/** Performs unsigned comparison "this <= arg".181(FIXME: should this work for OopHandles?) */182public boolean lessThanOrEqual (Address arg);183/** Performs unsigned comparison "this > arg".184(FIXME: should this work for OopHandles?) */185public boolean greaterThan (Address arg);186/** Performs unsigned comparison "this >= arg".187(FIXME: should this work for OopHandles?) */188public boolean greaterThanOrEqual(Address arg);189190/** This throws an UnsupportedOperationException if this address happens191to actually be an OopHandle. Performs a logical "and" operation192of the bits of the address and the mask (least significant bits193of the Address and the mask are aligned) and returns the result194as an Address. Returns null if the result was zero. */195public Address andWithMask(long mask) throws UnsupportedOperationException;196197/** This throws an UnsupportedOperationException if this address happens198to actually be an OopHandle. Performs a logical "or" operation199of the bits of the address and the mask (least significant bits200of the Address and the mask are aligned) and returns the result201as an Address. Returns null if the result was zero. */202public Address orWithMask(long mask) throws UnsupportedOperationException;203204/** This throws an UnsupportedOperationException if this address happens205to actually be an OopHandle. Performs a logical "exclusive or"206operation of the bits of the address and the mask (least207significant bits of the Address and the mask are aligned) and208returns the result as an Address. Returns null if the result was209zero. */210public Address xorWithMask(long mask) throws UnsupportedOperationException;211212// return address as long integer.213public long asLongValue();214}215216217