Skip to content

Commit

Permalink
Merge pull request #203 from Postremus/issues/45631-various-improvements
Browse files Browse the repository at this point in the history
Various performance improvements
  • Loading branch information
dmlloyd authored Feb 5, 2025
2 parents 3fc9e94 + 2d367e4 commit 5c36d91
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
24 changes: 16 additions & 8 deletions src/main/java/io/quarkus/gizmo/BytecodeCreatorImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -1047,9 +1047,9 @@ void loadResultHandle(MethodVisitor methodVisitor, ResultHandle handle, Bytecode
}
return;
}
if (!isScopedWithin(handle.getOwner())) {
// throw new IllegalStateException("Wrong owner for ResultHandle " + handle);
}
//if (!isScopedWithin(handle.getOwner())) {
// throw new IllegalStateException("Wrong owner for ResultHandle " + handle);
//}
if (handle.getResultType() != ResultHandle.ResultType.SINGLE_USE) {
if (handle.getType().equals("S") || handle.getType().equals("Z") || handle.getType().equals("I")
|| handle.getType().equals("B") || handle.getType().equals("C")) {
Expand Down Expand Up @@ -1692,16 +1692,22 @@ void findActiveResultHandles(Set<ResultHandle> handlesToAllocate) {
Operation prev = null;
for (int i = 0; i < operations.size(); ++i) {
Operation op = operations.get(i);
Set<ResultHandle> toAdd = new LinkedHashSet<>(op.getInputResultHandles());

ResultHandle resultHandleToIgnore = null;
if (prev != null &&
prev.getOutgoingResultHandle() != null &&
prev.getOutgoingResultHandle() == op.getTopResultHandle()) {
toAdd.remove(op.getTopResultHandle());
resultHandleToIgnore = op.getTopResultHandle();
if (op.getTopResultHandle().getResultType() == ResultHandle.ResultType.UNUSED) {
op.getTopResultHandle().markSingleUse();
}
}
handlesToAllocate.addAll(toAdd);

for (ResultHandle inputResultHandle : op.getInputResultHandles()) {
if (inputResultHandle != resultHandleToIgnore) {
handlesToAllocate.add(inputResultHandle);
}
}
op.findResultHandles(handlesToAllocate);
prev = op;
}
Expand Down Expand Up @@ -1813,10 +1819,12 @@ private ResultHandle[] requireNonNullHandles(ResultHandle[] handles) {

static abstract class Operation {

private static final boolean ARC_DEBUG = Boolean.getBoolean("arc.debug");

private final Throwable errorPoint;

Operation() {
if (Boolean.getBoolean("arc.debug")) {
if (ARC_DEBUG) {
errorPoint = new RuntimeException("Error location");
} else {
errorPoint = null;
Expand Down Expand Up @@ -1959,7 +1967,7 @@ Set<ResultHandle> getInputResultHandles() {
if (object != null) {
ret.add(object);
}
ret.addAll(Arrays.asList(args));
Collections.addAll(ret, args);
return ret;
}

Expand Down
12 changes: 7 additions & 5 deletions src/main/java/io/quarkus/gizmo/ResultHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ public class ResultHandle {
}

private void verifyType(String current) {
if (current.length() == 0) {
if (current.isEmpty()) {
throw new RuntimeException("Invalid type " + type);
}
if (current.length() == 1) {
switch (current.charAt(0)) {
int length = current.length();
char firstChar = current.charAt(0);
if (length == 1) {
switch (firstChar) {
case 'Z':
case 'B':
case 'S':
Expand All @@ -75,10 +77,10 @@ private void verifyType(String current) {
throw new RuntimeException("Invalid type " + type);
}
} else {
if (current.charAt(0) == '[') {
if (firstChar == '[') {
verifyType(current.substring(1));
} else {
if (!(current.startsWith("L") && current.endsWith(";"))) {
if (!(firstChar == 'L' && current.charAt(length - 1) == ';')) {
throw new RuntimeException("Invalid type " + type);
}
}
Expand Down

0 comments on commit 5c36d91

Please sign in to comment.