Skip to content

Commit ffa7155

Browse files
committed
Bring back presto-bytecode
1 parent 55bec7e commit ffa7155

File tree

86 files changed

+12910
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+12910
-1
lines changed

pom.xml

+27-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
<dep.logback.version>1.2.3</dep.logback.version>
6060
<dep.parquet.version>1.10.0</dep.parquet.version>
6161
<dep.nexus-staging-plugin.version>1.6.8</dep.nexus-staging-plugin.version>
62+
<dep.asm.version>6.2.1</dep.asm.version>
6263

6364
<!--
6465
America/Bahia_Banderas has:
@@ -104,6 +105,7 @@
104105
<module>presto-redshift</module>
105106
<module>presto-sqlserver</module>
106107
<module>presto-mongodb</module>
108+
<module>presto-bytecode</module>
107109
<module>presto-client</module>
108110
<module>presto-parser</module>
109111
<module>presto-main</module>
@@ -310,6 +312,12 @@
310312
<version>${project.version}</version>
311313
</dependency>
312314

315+
<dependency>
316+
<groupId>com.facebook.presto</groupId>
317+
<artifactId>presto-bytecode</artifactId>
318+
<version>${project.version}</version>
319+
</dependency>
320+
313321
<dependency>
314322
<groupId>com.facebook.presto</groupId>
315323
<artifactId>presto-client</artifactId>
@@ -677,7 +685,25 @@
677685
<dependency>
678686
<groupId>org.ow2.asm</groupId>
679687
<artifactId>asm</artifactId>
680-
<version>6.2.1</version>
688+
<version>${dep.asm.version}</version>
689+
</dependency>
690+
691+
<dependency>
692+
<groupId>org.ow2.asm</groupId>
693+
<artifactId>asm-tree</artifactId>
694+
<version>${dep.asm.version}</version>
695+
</dependency>
696+
697+
<dependency>
698+
<groupId>org.ow2.asm</groupId>
699+
<artifactId>asm-util</artifactId>
700+
<version>${dep.asm.version}</version>
701+
</dependency>
702+
703+
<dependency>
704+
<groupId>org.ow2.asm</groupId>
705+
<artifactId>asm-analysis</artifactId>
706+
<version>${dep.asm.version}</version>
681707
</dependency>
682708

683709
<dependency>

presto-bytecode/pom.xml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<parent>
6+
<groupId>com.facebook.presto</groupId>
7+
<artifactId>presto-root</artifactId>
8+
<version>0.222-SNAPSHOT</version>
9+
</parent>
10+
11+
<artifactId>presto-bytecode</artifactId>
12+
<name>presto-bytecode</name>
13+
14+
<properties>
15+
<air.main.basedir>${project.parent.basedir}</air.main.basedir>
16+
</properties>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>org.ow2.asm</groupId>
21+
<artifactId>asm</artifactId>
22+
</dependency>
23+
24+
<dependency>
25+
<groupId>org.ow2.asm</groupId>
26+
<artifactId>asm-tree</artifactId>
27+
</dependency>
28+
29+
<dependency>
30+
<groupId>org.ow2.asm</groupId>
31+
<artifactId>asm-util</artifactId>
32+
</dependency>
33+
34+
<!-- this undeclared dependency is used by asm-util -->
35+
<dependency>
36+
<groupId>org.ow2.asm</groupId>
37+
<artifactId>asm-analysis</artifactId>
38+
<scope>runtime</scope>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>com.google.code.findbugs</groupId>
43+
<artifactId>jsr305</artifactId>
44+
<optional>true</optional>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>com.google.guava</groupId>
49+
<artifactId>guava</artifactId>
50+
</dependency>
51+
52+
<!-- for testing -->
53+
<dependency>
54+
<groupId>org.testng</groupId>
55+
<artifactId>testng</artifactId>
56+
<scope>test</scope>
57+
</dependency>
58+
59+
<dependency>
60+
<groupId>org.assertj</groupId>
61+
<artifactId>assertj-core</artifactId>
62+
<scope>test</scope>
63+
</dependency>
64+
</dependencies>
65+
66+
<build>
67+
<plugins>
68+
<plugin>
69+
<groupId>com.mycila</groupId>
70+
<artifactId>license-maven-plugin</artifactId>
71+
<configuration>
72+
<excludes combine.children="append">
73+
<exclude>src/main/java/com/facebook/presto/bytecode/ClassInfo.java</exclude>
74+
<exclude>src/main/java/com/facebook/presto/bytecode/ClassInfoLoader.java</exclude>
75+
</excludes>
76+
</configuration>
77+
</plugin>
78+
</plugins>
79+
</build>
80+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.bytecode;
15+
16+
import com.google.common.collect.ImmutableList;
17+
18+
import java.util.EnumSet;
19+
20+
import static java.util.Locale.ENGLISH;
21+
import static org.objectweb.asm.Opcodes.ACC_ABSTRACT;
22+
import static org.objectweb.asm.Opcodes.ACC_ANNOTATION;
23+
import static org.objectweb.asm.Opcodes.ACC_BRIDGE;
24+
import static org.objectweb.asm.Opcodes.ACC_ENUM;
25+
import static org.objectweb.asm.Opcodes.ACC_FINAL;
26+
import static org.objectweb.asm.Opcodes.ACC_INTERFACE;
27+
import static org.objectweb.asm.Opcodes.ACC_NATIVE;
28+
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
29+
import static org.objectweb.asm.Opcodes.ACC_PROTECTED;
30+
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
31+
import static org.objectweb.asm.Opcodes.ACC_STATIC;
32+
import static org.objectweb.asm.Opcodes.ACC_STRICT;
33+
import static org.objectweb.asm.Opcodes.ACC_SUPER;
34+
import static org.objectweb.asm.Opcodes.ACC_SYNCHRONIZED;
35+
import static org.objectweb.asm.Opcodes.ACC_SYNTHETIC;
36+
import static org.objectweb.asm.Opcodes.ACC_TRANSIENT;
37+
import static org.objectweb.asm.Opcodes.ACC_VARARGS;
38+
import static org.objectweb.asm.Opcodes.ACC_VOLATILE;
39+
40+
public enum Access
41+
{
42+
PUBLIC(ACC_PUBLIC),
43+
PRIVATE(ACC_PRIVATE),
44+
PROTECTED(ACC_PROTECTED),
45+
STATIC(ACC_STATIC),
46+
FINAL(ACC_FINAL),
47+
SUPER(ACC_SUPER),
48+
SYNCHRONIZED(ACC_SYNCHRONIZED),
49+
VOLATILE(ACC_VOLATILE),
50+
BRIDGE(ACC_BRIDGE),
51+
VARARGS(ACC_VARARGS),
52+
TRANSIENT(ACC_TRANSIENT),
53+
NATIVE(ACC_NATIVE),
54+
INTERFACE(ACC_INTERFACE),
55+
ABSTRACT(ACC_ABSTRACT),
56+
STRICT(ACC_STRICT),
57+
SYNTHETIC(ACC_SYNTHETIC),
58+
ANNOTATION(ACC_ANNOTATION),
59+
ENUM(ACC_ENUM);
60+
61+
private final int modifier;
62+
63+
Access(int modifier)
64+
{
65+
this.modifier = modifier;
66+
}
67+
68+
public int getModifier()
69+
{
70+
return modifier;
71+
}
72+
73+
@Override
74+
public String toString()
75+
{
76+
return name().toLowerCase(ENGLISH);
77+
}
78+
79+
public static EnumSet<Access> a(Access... access)
80+
{
81+
return EnumSet.copyOf(ImmutableList.copyOf(access));
82+
}
83+
84+
public static int toAccessModifier(Iterable<Access> accesses)
85+
{
86+
int modifier = 0;
87+
for (Access access : accesses) {
88+
modifier += access.getModifier();
89+
}
90+
return modifier;
91+
}
92+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package com.facebook.presto.bytecode;
15+
16+
import org.objectweb.asm.ClassVisitor;
17+
import org.objectweb.asm.Handle;
18+
import org.objectweb.asm.Label;
19+
import org.objectweb.asm.MethodVisitor;
20+
21+
import static org.objectweb.asm.Opcodes.ASM5;
22+
23+
class AddFakeLineNumberClassVisitor
24+
extends ClassVisitor
25+
{
26+
int methodCount;
27+
28+
public AddFakeLineNumberClassVisitor(ClassVisitor cv)
29+
{
30+
super(ASM5, cv);
31+
super.visitSource("FakeSource.java", null);
32+
}
33+
34+
@Override
35+
public void visitSource(String source, String debug)
36+
{
37+
super.visitSource(source, debug);
38+
}
39+
40+
@Override
41+
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions)
42+
{
43+
MethodVisitor methodVisitor = cv.visitMethod(access, name, desc, signature, exceptions);
44+
methodCount++;
45+
return new AddFakeLineNumberMethodVisitor(methodVisitor, 1000 * methodCount);
46+
}
47+
48+
private static class AddFakeLineNumberMethodVisitor
49+
extends MethodVisitor
50+
{
51+
private int count;
52+
53+
public AddFakeLineNumberMethodVisitor(MethodVisitor mv, int startLineNumber)
54+
{
55+
super(ASM5, mv);
56+
this.count = startLineNumber;
57+
}
58+
59+
private void addFakeLineNumber()
60+
{
61+
Label label = new Label();
62+
mv.visitLabel(label);
63+
mv.visitLineNumber(++count, label);
64+
}
65+
66+
@Override
67+
public void visitInsn(int opcode)
68+
{
69+
addFakeLineNumber();
70+
super.visitInsn(opcode);
71+
}
72+
73+
@Override
74+
public void visitIntInsn(int opcode, int operand)
75+
{
76+
addFakeLineNumber();
77+
super.visitIntInsn(opcode, operand);
78+
}
79+
80+
@Override
81+
public void visitVarInsn(int opcode, int var)
82+
{
83+
addFakeLineNumber();
84+
super.visitVarInsn(opcode, var);
85+
}
86+
87+
@Override
88+
public void visitTypeInsn(int opcode, String type)
89+
{
90+
addFakeLineNumber();
91+
super.visitTypeInsn(opcode, type);
92+
}
93+
94+
@Override
95+
public void visitFieldInsn(int opcode, String owner, String name, String desc)
96+
{
97+
addFakeLineNumber();
98+
super.visitFieldInsn(opcode, owner, name, desc);
99+
}
100+
101+
@Override
102+
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf)
103+
{
104+
addFakeLineNumber();
105+
super.visitMethodInsn(opcode, owner, name, desc, itf);
106+
}
107+
108+
@Override
109+
public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs)
110+
{
111+
addFakeLineNumber();
112+
super.visitInvokeDynamicInsn(name, desc, bsm, bsmArgs);
113+
}
114+
115+
@Override
116+
public void visitJumpInsn(int opcode, Label label)
117+
{
118+
addFakeLineNumber();
119+
super.visitJumpInsn(opcode, label);
120+
}
121+
122+
@Override
123+
public void visitLdcInsn(Object cst)
124+
{
125+
addFakeLineNumber();
126+
super.visitLdcInsn(cst);
127+
}
128+
129+
@Override
130+
public void visitIincInsn(int var, int increment)
131+
{
132+
addFakeLineNumber();
133+
super.visitIincInsn(var, increment);
134+
}
135+
136+
@Override
137+
public void visitTableSwitchInsn(int min, int max, Label dflt, Label... labels)
138+
{
139+
addFakeLineNumber();
140+
super.visitTableSwitchInsn(min, max, dflt, labels);
141+
}
142+
143+
@Override
144+
public void visitLookupSwitchInsn(Label dflt, int[] keys, Label[] labels)
145+
{
146+
addFakeLineNumber();
147+
super.visitLookupSwitchInsn(dflt, keys, labels);
148+
}
149+
150+
@Override
151+
public void visitMultiANewArrayInsn(String desc, int dims)
152+
{
153+
addFakeLineNumber();
154+
super.visitMultiANewArrayInsn(desc, dims);
155+
}
156+
}
157+
}

0 commit comments

Comments
 (0)