Skip to content

Commit

Permalink
8269957: facilitate alternate impls of NameTable and Name
Browse files Browse the repository at this point in the history
Reviewed-by: jjg, vromero
  • Loading branch information
Archie Cobbs authored and Vicente Romero committed Aug 28, 2023
1 parent 725ec0c commit 11da15d
Show file tree
Hide file tree
Showing 11 changed files with 672 additions and 263 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5192,7 +5192,7 @@ public void assembleClassSig(Type type) {
append(rawOuter ? '$' : '.');
Assert.check(c.flatname.startsWith(c.owner.enclClass().flatname));
append(rawOuter
? c.flatname.subName(c.owner.enclClass().flatname.getByteLength() + 1, c.flatname.getByteLength())
? c.flatname.subName(c.owner.enclClass().flatname.length() + 1)
: c.name);
} else {
append(externalize(c.flatname));
Expand Down
10 changes: 5 additions & 5 deletions src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class Gen extends JCTree.Visitor {
private final TreeMaker make;
private final Names names;
private final Target target;
private final Name accessDollar;
private final String accessDollar;
private final Types types;
private final Lower lower;
private final Annotate annotate;
Expand Down Expand Up @@ -112,8 +112,7 @@ protected Gen(Context context) {
concat = StringConcat.instance(context);

methodType = new MethodType(null, null, null, syms.methodClass);
accessDollar = names.
fromString("access" + target.syntheticNameChar());
accessDollar = "access" + target.syntheticNameChar();
lower = Lower.instance(context);

Options options = Options.instance(context);
Expand Down Expand Up @@ -341,9 +340,10 @@ private boolean isAccessSuper(JCMethodDecl enclMethod) {
/** Does given name start with "access$" and end in an odd digit?
*/
private boolean isOddAccessName(Name name) {
final String string = name.toString();
return
name.startsWith(accessDollar) &&
(name.getByteAt(name.getByteLength() - 1) & 1) == 1;
string.startsWith(accessDollar) &&
(string.charAt(string.length() - 1) & 1) != 0;
}

/* ************************************************************************
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import com.sun.tools.javac.util.ByteBuffer;
import com.sun.tools.javac.util.ByteBuffer.UnderflowException;
import com.sun.tools.javac.util.Convert;
import com.sun.tools.javac.util.Name.NameMapper;

import java.io.IOException;
import java.io.InputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,13 @@ public void appendDouble(double x) {
}
}

/** Append a name.
/** Append a name encoded in Modified UTF-8.
*/
public void appendName(Name name) {
appendBytes(name.getByteArray(), name.getByteOffset(), name.getByteLength());
int utf8len = name.getUtf8Length();
elems = ArrayUtils.ensureCapacity(elems, length + utf8len);
name.getUtf8Bytes(elems, length);
length += utf8len;
}

/** Append the content of the given input stream.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,24 @@ public static String utf2string(byte[] src, int sindex, int len, Validation vali
return new String(dst, 0, len1);
}

/** Count the number of characters encoded in a Modified UTF-8 encoding.
* This method does not check for invalid data.
* @param buf data buffer
* @param off starting offset of UTF-8 data
* @param len number of bytes of UTF-8 data
* @return the number of encoded characters
*/
public static int utfNumChars(byte[] buf, int off, int len) {
int numChars = 0;
while (len-- > 0) {
int byte1 = buf[off++];
if (byte1 < 0)
len -= ((byte1 & 0xe0) == 0xc0) ? 1 : 2;
numChars++;
}
return numChars;
}

/** Copy characters in source array to bytes in target array,
* converting them to Utf8 representation.
* The target array must be large enough to hold the result.
Expand Down Expand Up @@ -346,17 +364,14 @@ public static String escapeUnicode(String s) {

/* Conversion routines for qualified name splitting
*/

/** Return the last part of a qualified name.
* @param name the qualified name
* @return the last part of the qualified name
*/
public static Name shortName(Name name) {
int start = name.lastIndexOf((byte)'.') + 1;
int end = name.getByteLength();
if (start == 0 && end == name.length()) {
return name;
}
return name.subName(start, end);
int start = name.lastIndexOfAscii('.') + 1;
return start > 0 ? name.subName(start) : name;
}

/** Return the last part of a qualified name from its string representation
Expand All @@ -371,7 +386,8 @@ public static String shortName(String name) {
* "" if not existent.
*/
public static Name packagePart(Name classname) {
return classname.subName(0, classname.lastIndexOf((byte)'.'));
int end = Math.max(classname.lastIndexOfAscii('.'), 0);
return classname.subName(0, end);
}

public static String packagePart(String classname) {
Expand All @@ -382,7 +398,7 @@ public static String packagePart(String classname) {
public static List<Name> enclosingCandidates(Name name) {
List<Name> names = List.nil();
int index;
while ((index = name.lastIndexOf((byte)'$')) > 0) {
while ((index = name.lastIndexOfAscii('$')) > 0) {
name = name.subName(0, index);
names = names.prepend(name);
}
Expand Down

1 comment on commit 11da15d

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.