Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate bootstrap method inside proxy class #11

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
java: ['8', '11', '15']
java: ['11', '15']
steps:
- uses: actions/checkout@v2
- name: Setup JDK ${{ matrix.java }}
Expand Down
7 changes: 5 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>io.airlift</groupId>
<artifactId>airbase</artifactId>
<version>83</version>
<version>104</version>
</parent>

<artifactId>bytecode</artifactId>
Expand All @@ -20,7 +20,10 @@
<air.check.skip-spotbugs>true</air.check.skip-spotbugs>
<air.check.skip-pmd>true</air.check.skip-pmd>

<dep.asm.version>6.2.1</dep.asm.version>
<project.build.targetJdk>11</project.build.targetJdk>
<air.modernizer.java-version>8</air.modernizer.java-version>

<dep.asm.version>9.0</dep.asm.version>
</properties>

<dependencies>
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/io/airlift/bytecode/AnnotationDefinition.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package io.airlift.bytecode;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.primitives.Primitives;
import org.objectweb.asm.AnnotationVisitor;
Expand All @@ -28,6 +27,7 @@
import java.util.Map.Entry;
import java.util.Set;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.bytecode.ParameterizedType.type;
import static java.util.Objects.requireNonNull;

Expand Down Expand Up @@ -152,14 +152,14 @@ private static void isValidType(Object value)
if (value instanceof List) {
// todo verify list contains single type
for (Object v : (List<Object>) value) {
Preconditions.checkArgument(ALLOWED_TYPES.contains(v.getClass()), "List contains invalid type %s", v.getClass());
checkArgument(ALLOWED_TYPES.contains(v.getClass()), "List contains invalid type %s", v.getClass());
if (v instanceof List) {
isValidType(value);
}
}
}
else {
Preconditions.checkArgument(ALLOWED_TYPES.contains(value.getClass()), "Invalid value type %s", value.getClass());
checkArgument(ALLOWED_TYPES.contains(value.getClass()), "Invalid value type %s", value.getClass());
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/main/java/io/airlift/bytecode/BytecodeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import io.airlift.bytecode.debug.LineNumberNode;
import io.airlift.bytecode.instruction.Constant;
import io.airlift.bytecode.instruction.InvokeInstruction;
import io.airlift.bytecode.instruction.InvokeInstruction.BootstrapMethod;
import io.airlift.bytecode.instruction.JumpInstruction;
import io.airlift.bytecode.instruction.LabelNode;
import io.airlift.bytecode.instruction.TypeInstruction;
Expand Down Expand Up @@ -494,6 +495,17 @@ public BytecodeNode invokeDynamic(String name,
return this;
}

public BytecodeBlock invokeDynamic(
String name,
ParameterizedType returnType,
Iterable<ParameterizedType> parameterTypes,
BootstrapMethod bootstrapMethod,
List<Object> bootstrapArgs)
{
nodes.add(InvokeInstruction.invokeDynamic(name, returnType, parameterTypes, bootstrapMethod, bootstrapArgs));
return this;
}

public BytecodeBlock ret(Class<?> type)
{
if (type == long.class) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/airlift/bytecode/ClassInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
*/
package io.airlift.bytecode;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.MethodNode;

import java.util.List;

import static com.google.common.base.Preconditions.checkState;
import static com.google.common.collect.Iterables.transform;
import static io.airlift.bytecode.ParameterizedType.type;
import static io.airlift.bytecode.ParameterizedType.typeFromPathName;
Expand Down Expand Up @@ -126,7 +126,7 @@ public List<ClassInfo> getInterfaces()

public List<MethodNode> getMethods()
{
Preconditions.checkState(methods != null, "Methods were not loaded for type %s", type);
checkState(methods != null, "Methods were not loaded for type %s", type);
return methods;
}

Expand Down
16 changes: 12 additions & 4 deletions src/main/java/io/airlift/bytecode/DynamicClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*/
package io.airlift.bytecode;

import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Sets;
import com.google.common.collect.Sets.SetView;
Expand All @@ -25,6 +24,8 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import static com.google.common.base.Preconditions.checkArgument;

public class DynamicClassLoader
extends ClassLoader
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public Class<?> defineClass(String className, byte[] bytecode)
public Map<String, Class<?>> defineClasses(Map<String, byte[]> newClasses)
{
SetView<String> conflicts = Sets.intersection(pendingClasses.keySet(), newClasses.keySet());
Preconditions.checkArgument(conflicts.isEmpty(), "The classes %s have already been defined", conflicts);
checkArgument(conflicts.isEmpty(), "The classes %s have already been defined", conflicts);

pendingClasses.putAll(newClasses);
try {
Expand Down Expand Up @@ -127,8 +128,15 @@ protected Class<?> loadClass(String name, boolean resolve)
}
}

Class<?> clazz = getParent().loadClass(name);
return resolveClass(clazz, resolve);
// try parent if present
ClassLoader parent = getParent();
if (parent != null) {
Class<?> clazz = parent.loadClass(name);
return resolveClass(clazz, resolve);
}

// try bootstrap class loader
return super.loadClass(name, resolve);
}
}

Expand Down
Loading