public final class Atom extends Object
Atom's are interned (canonicalized) so they may be compared for equality using the "==" operator.
Atoms are used to represent names, descriptors, and string literals appearing in a class's constant pool.
There is almost always a zero-length Atom, since any class which contains statements like:
return "";will have one in its constant pool.
Modifier and Type | Class and Description |
---|---|
private static class |
Atom.InternedStrings
Inner class responsible for string interning.
|
Modifier and Type | Field and Description |
---|---|
private static Atom[][] |
atoms
Dictionary of all Atom instances.
|
private static byte[][] |
BOOTSTRAP_CLASS_PREFIX_SET
The set of class prefixes that MUST be loaded by bootstrap classloader.
|
private static ImmutableEntryHashMapRVM<Atom,Atom> |
dictionary
Used to canonicalize Atoms: possibly non-canonical Atom => Atom
|
private int |
id
The id of this atom
|
private static int |
LOG_ROW_SIZE
2^LOG_ROW_SIZE is the number of elements per row
|
private static int |
nextId
Used to assign ids.
|
private static byte[][] |
NON_BOOTSTRAP_CLASS_PREFIX_SET
The set of class prefixes that MUST NOT be loaded by bootstrap classloader.
|
private static int |
ROW_MASK
Mask to ascertain row from id number
|
private static byte[][] |
RVM_CLASS_PREFIXES
The set of class prefixes for core RVM classes.
|
private Object |
unicodeStringOrJTOCoffset
A reference to either a unicode String encoding the atom, an offset in the
JTOC holding a unicode string encoding the atom or null.
|
private byte[] |
val
The utf8 value this atom represents
|
Modifier | Constructor and Description |
---|---|
private |
Atom(byte[] val,
int id,
String str) |
Modifier and Type | Method and Description |
---|---|
String |
annotationClassToAnnotationInterface()
Creates a class name from a type name.
|
Atom |
annotationInterfaceToAnnotationClass()
Creates an annotation name from a class name.
|
(package private) Atom |
arrayDescriptorFromElementDescriptor()
Return array descriptor corresponding to "this" array-element descriptor.
|
String |
classFileNameFromDescriptor()
Return name of class file corresponding to "this" class descriptor.
|
String |
classNameFromDescriptor()
Return class name corresponding to "this" class descriptor.
|
Atom |
descriptorFromClassName()
Return class descriptor corresponding to "this" class name.
|
boolean |
equals(Object other)
Outside of this class atoms are canonical and should be compared using ==.
|
static Atom |
findAsciiAtom(String str)
Find an atom.
|
private static Atom |
findOrCreate(byte[] bytes,
boolean create,
String str)
This is the findOrCreate() method through which all Atoms are
ultimately created.
|
private static Atom |
findOrCreate(byte[] utf8,
int off,
int len,
String str)
Find an atom from the subsequence of another
|
static Atom |
findOrCreateAsciiAtom(String str)
Find or create an atom.
|
static Atom |
findOrCreateUnicodeAtom(String str)
Find or create an atom.
|
static Atom |
findOrCreateUtf8Atom(byte[] utf8)
Find or create an atom.
|
static Atom |
findUnicodeAtom(String str)
Find an atom.
|
static Atom |
findUtf8Atom(byte[] utf8)
Find an atom.
|
static Atom |
getAtom(int id) |
byte[] |
getBytes() |
(package private) int |
getId() |
int |
getStringLiteralOffset()
Offset of an atom's string in the JTOC, for string literals
|
int |
hashCode()
Return the hashCode of an atom, this equals the unicode string encoding of
the atom
|
static String |
internString(String str)
External string intern method called from String.intern.
|
boolean |
isAnnotationClass() |
boolean |
isArrayDescriptor() |
boolean |
isBootstrapClassDescriptor() |
boolean |
isClassDescriptor() |
boolean |
isMethodDescriptor() |
boolean |
isReservedMemberName()
Note: Sun has reserved all member names starting with '<' for future use.
|
boolean |
isRVMDescriptor() |
int |
length() |
int |
parseForArrayDimensionality()
Parse "this" array descriptor to obtain number of dimensions in
corresponding array type.
|
Atom |
parseForArrayElementDescriptor()
Parse "this" array descriptor to obtain descriptor for array's element
type.
|
byte |
parseForArrayElementTypeCode()
Parse "this" array descriptor to obtain type code for its element type.
|
Atom |
parseForInnermostArrayElementDescriptor() |
Class<?>[] |
parseForParameterClasses(ClassLoader cl)
Parse "this" method descriptor to obtain descriptions of method's
parameters as classes.
|
TypeReference[] |
parseForParameterTypes(ClassLoader cl)
Parse "this" method descriptor to obtain descriptions of method's
parameters.
|
TypeReference |
parseForReturnType(ClassLoader cl)
Parse "this" method descriptor to obtain description of method's
return type.
|
byte |
parseForTypeCode()
Parse "this" field, parameter, or return descriptor to obtain its
type code.
|
void |
sysWrite() |
byte[] |
toByteArray()
Get at a string-like representation without doing any heap allocation.
|
String |
toString()
Return printable representation of "this" atom.
|
String |
toUnicodeString() |
private String |
toUnicodeStringInternal() |
private static final ImmutableEntryHashMapRVM<Atom,Atom> dictionary
private static final int LOG_ROW_SIZE
private static final int ROW_MASK
private static int nextId
private Object unicodeStringOrJTOCoffset
private final byte[] val
private final int id
private static final byte[][] BOOTSTRAP_CLASS_PREFIX_SET
isBootstrapClassDescriptor()
private static final byte[][] NON_BOOTSTRAP_CLASS_PREFIX_SET
isBootstrapClassDescriptor()
private static final byte[][] RVM_CLASS_PREFIXES
isRVMDescriptor()
int getId()
public static Atom findOrCreateUnicodeAtom(String str)
str
- atom value, as string literal whose characters are unicodepublic static Atom findUnicodeAtom(String str)
str
- atom value, as string literal whose characters are unicodepublic static Atom findOrCreateAsciiAtom(String str)
str
- atom value, as string literal whose characters are from
ascii subset of unicode (not including null)public static Atom findAsciiAtom(String str)
str
- atom value, as string literal whose characters are from
ascii subset of unicode (not including null)public static Atom findOrCreateUtf8Atom(byte[] utf8)
utf8
- atom value, as utf8 encoded bytespublic static Atom findUtf8Atom(byte[] utf8)
utf8
- atom value, as utf8 encoded bytesprivate static Atom findOrCreate(byte[] utf8, int off, int len, String str)
utf8
- byte backing of atomoff
- offset of new atomlen
- length of new atomstr
- possible string encoding of atom or nullprivate static Atom findOrCreate(byte[] bytes, boolean create, String str)
Note: either bytes or str will be null but not both at the same time.
bytes
- content of atom as utf8 bytescreate
- whether an atom should be created if none can be foundstr
- string encoding of atomnull
if no atom was found and create is false, an atom
otherwisepublic static Atom getAtom(int id)
id
- the id of an Atompublic String toString()
public byte[] toByteArray()
public String toUnicodeString() throws UTFDataFormatException
UTFDataFormatException
- when conversion of the atom
to an UTF8 string failsprivate String toUnicodeStringInternal()
null
if atom hasn't been convertedpublic int getStringLiteralOffset() throws UTFDataFormatException
UTFDataFormatException
- when conversion of the atom
to an UTF8 string failsAtom arrayDescriptorFromElementDescriptor()
public Atom descriptorFromClassName()
public String classNameFromDescriptor()
public String classFileNameFromDescriptor()
public boolean isReservedMemberName()
<init>
and <clinit>
are used.public boolean isClassDescriptor()
true
if "this" atom is a class descriptorpublic boolean isArrayDescriptor()
true
if "this" atom is an array descriptorpublic boolean isMethodDescriptor()
true
if "this" atom is a method descriptorpublic TypeReference parseForReturnType(ClassLoader cl)
cl
- the classloaderTypeReference.findOrCreate(ClassLoader, Atom)
public TypeReference[] parseForParameterTypes(ClassLoader cl)
cl
- the classloaderTypeReference.findOrCreate(ClassLoader, Atom)
public Class<?>[] parseForParameterClasses(ClassLoader cl)
cl
- the classloaderpublic byte[] getBytes()
public byte parseForTypeCode() throws IllegalArgumentException
constant value ---------------- ----- ClassTypeCode 'L' ArrayTypeCode '[' VoidTypeCode 'V' BooleanTypeCode 'Z' ByteTypeCode 'B' ShortTypeCode 'S' IntTypeCode 'I' LongTypeCode 'J' FloatTypeCode 'F' DoubleTypeCode 'D' CharTypeCode 'C'
IllegalArgumentException
public int parseForArrayDimensionality()
public byte parseForArrayElementTypeCode()
public Atom parseForInnermostArrayElementDescriptor()
public Atom parseForArrayElementDescriptor()
public boolean isBootstrapClassDescriptor()
public boolean isRVMDescriptor()
true
if this is a class descriptor of a RVM core class.
This is defined as one that it would be unwise to invalidate, since invalidating
it might make it impossible to recompile.public Atom annotationInterfaceToAnnotationClass()
public String annotationClassToAnnotationInterface()
public boolean isAnnotationClass()
public void sysWrite()
public int length()
public int hashCode()
public boolean equals(Object other)
public static String internString(String str)
str
- string to intern