Skip to content

Commit a9d8931

Browse files
committed
0.3.0 - Update to Java 9 and support for class file changes in Java 9. Combined several attribute classes, simplified tag and fields in constantPool classes to single 'TAG' field. Renamed UnitTest -> UsageCliMain and added some more functionality for playing with class file parsing.
1 parent 555e988 commit a9d8931

File tree

78 files changed

+2457
-1478
lines changed

Some content is hidden

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

78 files changed

+2457
-1478
lines changed

.classpath

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" path="src"/>
4-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre-9.0.1">
5+
<attributes>
6+
<attribute name="module" value="true"/>
7+
</attributes>
8+
</classpathentry>
59
<classpathentry kind="lib" path="C:/Users/TeamworkGuy2/Documents/Java/Libraries/java/eclipse/jar/ecj-4.4M2.jar"/>
610
<classpathentry kind="output" path="bin"/>
711
</classpath>

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,22 @@ This project does its best to adhere to [Semantic Versioning](http://semver.org/
44

55

66
--------
7-
### [0.2.1](N/A) - 2017-08-14
7+
### [0.3.0](N/A) - 2017-12-22
8+
#### Changed
9+
* Upgrade to Java 9
10+
* Java 9 ClassFile format support:
11+
* New Attributes: `Module`, `ModuleMainClass`, `ModulePackages`
12+
* New constant pool types: `CONSTANT_Module`, `CONSTANT_Package`
13+
* Renamed/changed the `public static final int CONSTANT_*_info` field to `public static final byte TAG` and removed the instanced `tag` field from all constantPool classes
14+
* Renamed `Target_Info_Type` -> `Target_Info_Union`
15+
* Consolidated `twg2.jbcm.classFormat.attributes`, nested classes that are only used by one class inside the class
16+
* Added/fixed several attributes' `toString()` methods
17+
* Cleaned up some attributes field documentation
18+
* Renamed `UnitTest` -> `UsageCliMain` and added support for printing dependencies and loading multiple classes, printing multiple classes, and clearing loaded classes
19+
20+
21+
--------
22+
### [0.2.1](https://github.com/TeamworkGuy2/ClassLoading/commit/555e988ff0c21d0510296cefd9b300d46fd6eb04) - 2017-08-14
823
#### Changed
924
* Forgot to update jar file
1025

README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
ClassLoading
22
==========
3-
version: 0.2.0
3+
version: 0.3.0
44

55
Java class file parsing and manipulation library.
6-
Reference: [Java Virtual Machine Spec](http://docs.oracle.com/javase/specs/jvms/se8/html/index.html)
6+
This library is mostly experimental for my own personal learning.
7+
It can load and save class files and lookup class file dependencies, but contains very little code for making changes to class files or validating those changes.
8+
See the `twg2.jbcm.main.UsageCliMain` class for a simple command line interface you can use to load and print info about class files.
9+
Reference: [Java Virtual Machine Spec (Java 9)](http://docs.oracle.com/javase/specs/jvms/se9/html/index.html)
710

811
### `twg2.jbcm.classFormat`
9-
Contains implementation of the [class file format](http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html)
10-
with related attributes and constant pool types.
12+
Contains implementation of the [class file format](http://docs.oracle.com/javase/specs/jvms/se9/html/jvms-4.html)
13+
with related attributes (`twg2.jbcm.classFormat.attributes`) and constant pool types (`twg2.jbcm.classFormat.constantPool`).
1114

1215
### `twg2.jbcm` and `twg2.jbcm.modify`
1316
Interfaces and utilities for searching and modifying class files.
1417

1518
### `twg2.jbcm.opcode`
16-
Partial implementation of [Java instruction set opcodes](http://docs.oracle.com/javase/specs/jvms/se8/html/jvms-6.html#jvms-6.5).
19+
Partial implementation of [Java instruction set opcodes](http://docs.oracle.com/javase/specs/jvms/se9/html/jvms-6.html#jvms-6.5).
1720

1821
### `twg2.jbcm.dynamicModification` and `twg2.jbcm.parserExamples`
1922
Classes used by the example and test packages.

bin/class_loading.jar

30.5 KB
Binary file not shown.

package-lib.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version" : "0.2.0",
2+
"version" : "0.3.0",
33
"name" : "class-loading",
44
"description" : "Java class file parsing and manipulation",
55
"homepage" : "https://github.com/TeamworkGuy2/ClassLoading",

src/twg2/jbcm/IoUtility.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ private static final int loadOperands(int numOperands, byte[] code, int index) {
252252

253253

254254
/** A default implementation of {@link CodeOffsetChanger}.
255-
* The {@link #accept(byte[], int, int)} in this implementation simply calls {@code IoUtility.shiftOffset(...)}
256-
* using the parameters from the constructor and the {@link CodeOffsetChanger#accept(byte[], int, int)} method.
255+
* The {@link CodeOffsetChanger#shiftIndex(byte[], int, int)} in this implementation simply calls {@code IoUtility.shiftOffset(...)}
256+
* using the parameters from the constructor and the {@link CodeOffsetChanger#shiftIndex(byte[], int, int)} method.
257257
* @author TeamworkGuy2
258258
* @since 2014-419
259259
*/

src/twg2/jbcm/classFormat/ClassFile.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,15 +175,22 @@ public String getCpString(int attributeNameIndex) {
175175

176176
public CpIndex<CONSTANT_CP_Info> getCpIndex(int index) {
177177
if(index > 0 && index < constant_pool_count) {
178-
CpIndex<CONSTANT_CP_Info> result = (CpIndex<CONSTANT_CP_Info>)constant_pool.get(index);
178+
CpIndex<CONSTANT_CP_Info> result = constant_pool.get(index);
179179
return result;
180180
}
181-
if(Settings.checkCPIndex) { throw new IllegalStateException("constant pool index " + index + " out of constant pool size bounds"); }
181+
if(Settings.checkCPIndex) {
182+
throw new IllegalStateException("constant pool index " + index + " out of constant pool size bounds");
183+
}
182184
return null;
183185
}
184186

185187

186188
public <T extends CONSTANT_CP_Info> CpIndex<T> getCheckCpIndex(int index, Class<T> clazz) {
189+
return getCheckCpIndex(index, clazz, false);
190+
}
191+
192+
193+
public <T extends CONSTANT_CP_Info> CpIndex<T> getCheckCpIndex(int index, Class<T> clazz, boolean allowZero) {
187194
if(index > 0 && index < constant_pool_count) {
188195
@SuppressWarnings("unchecked")
189196
CpIndex<T> result = (CpIndex<T>)constant_pool.get(index);
@@ -195,7 +202,9 @@ public <T extends CONSTANT_CP_Info> CpIndex<T> getCheckCpIndex(int index, Class<
195202
}
196203
return result;
197204
}
198-
if(Settings.checkCPIndex) { throw new IllegalStateException("constant pool index " + index + " out of constant pool size bounds"); }
205+
if(!allowZero && Settings.checkCPIndex) {
206+
throw new IllegalStateException("constant pool index " + index + " out of constant pool size bounds");
207+
}
199208
return null;
200209
}
201210

@@ -322,7 +331,9 @@ public <T extends CONSTANT_CP_Info> CpIndex<T> addToConstantPool(T cpObj) {
322331

323332

324333
public void setConstantPool(int index, CONSTANT_CP_Info cpObj) {
325-
if(index < 1 || index >= constant_pool_count) { throw new IndexOutOfBoundsException("Illegal class file constant pool index: " + index); }
334+
if(index < 1 || index >= constant_pool_count) {
335+
throw new IndexOutOfBoundsException("Illegal class file constant pool index: " + index);
336+
}
326337
constant_pool.get(index).setCpObject(cpObj);
327338
}
328339

@@ -368,6 +379,7 @@ public CONSTANT_Class getInterface(int index) {
368379
}
369380

370381

382+
@SuppressWarnings("unchecked")
371383
public void addInterface(CpIndex<CONSTANT_Class> interfaceClassIndex) {
372384
CONSTANT_CP_Info interfaceClass = interfaceClassIndex.getCpObject();
373385
if(!(interfaceClass instanceof CONSTANT_Class)) {
@@ -471,6 +483,7 @@ public void writeData(DataOutput out) throws IOException {
471483
}
472484

473485

486+
@SuppressWarnings("unchecked")
474487
@Override
475488
public void readData(DataInput in) throws IOException {
476489
magic = in.readInt();

src/twg2/jbcm/classFormat/ClassFileAttributes.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import twg2.jbcm.classFormat.attributes.LocalVariableTable;
1414
import twg2.jbcm.classFormat.attributes.LocalVariableTypeTable;
1515
import twg2.jbcm.classFormat.attributes.MethodParameters;
16+
import twg2.jbcm.classFormat.attributes.ModuleMainClass;
17+
import twg2.jbcm.classFormat.attributes.ModulePackages;
1618
import twg2.jbcm.classFormat.attributes.RuntimeInvisibleAnnotations;
1719
import twg2.jbcm.classFormat.attributes.RuntimeInvisibleParameterAnnotations;
1820
import twg2.jbcm.classFormat.attributes.RuntimeInvisibleTypeAnnotations;
@@ -81,7 +83,14 @@ public enum ClassFileAttributes {
8183
RUNTIME_INVISIBLE_TYPE_ANNOTATIONS("RuntimeInvisibleTypeAnnotations") {
8284
@Override public Attribute_Type create(ClassFile clazz, int cpNameIndex, Code code) { return new RuntimeInvisibleTypeAnnotations(clazz, (short)cpNameIndex); } },
8385
METHOD_PARAMETERS("MethodParameters") {
84-
@Override public Attribute_Type create(ClassFile clazz, int cpNameIndex, Code code) { return new MethodParameters(clazz, (short)cpNameIndex); } };
86+
@Override public Attribute_Type create(ClassFile clazz, int cpNameIndex, Code code) { return new MethodParameters(clazz, (short)cpNameIndex); } },
87+
// Java SE 9 (2017-12-22)
88+
MODULE("Module") {
89+
@Override public Attribute_Type create(ClassFile clazz, int cpNameIndex, Code code) { return new twg2.jbcm.classFormat.attributes.Module(clazz, (short)cpNameIndex); } },
90+
MODULE_PACKAGES("ModulePackages") {
91+
@Override public Attribute_Type create(ClassFile clazz, int cpNameIndex, Code code) { return new ModulePackages(clazz, (short)cpNameIndex); } },
92+
MODULE_MAIN_CLASS("ModuleMainClass") {
93+
@Override public Attribute_Type create(ClassFile clazz, int cpNameIndex, Code code) { return new ModuleMainClass(clazz, (short)cpNameIndex); } };
8594

8695

8796
private String binaryName;

src/twg2/jbcm/classFormat/CpIndex.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public int hashCode() {
128128

129129
@Override
130130
public String toString() {
131-
return "CpIndex(index=" + index + ", type=" + clas.toString() + ", value=" + getCpObject() + ")";
131+
return "CpIndex(index=" + index + ", value=" + getCpObject() + ")";
132132
}
133133

134134
}

src/twg2/jbcm/classFormat/attributes/Annotation.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,18 @@
1616
*/
1717
public class Annotation implements ReadWritable {
1818
ClassFile resolver;
19-
/* The value of the type_index item must be a valid index into the constant_pool table.
19+
/** The value of the type_index item must be a valid index into the constant_pool table.
2020
* The constant_pool entry at that index must be a CONSTANT_Utf8_info (§4.4.7) structure
2121
* representing a field descriptor representing the annotation type corresponding to
2222
* the annotation represented by this annotation structure.
2323
*/
2424
CpIndex<CONSTANT_Utf8> type_index;
25-
/* The value of the num_element_value_pairs item gives the number of element-value pairs of
25+
/** The value of the num_element_value_pairs item gives the number of element-value pairs of
2626
* the annotation represented by this annotation structure.
2727
* Note that a maximum of 65535 element-value pairs may be contained in a single annotation.
2828
*/
2929
short num_element_value_pairs;
30-
/* Each value of the element_value_pairs table represents a single element-value pair in the
30+
/** Each value of the element_value_pairs table represents a single element-value pair in the
3131
* annotation represented by this annotation structure. Each element_value_pairs entry contains
3232
* the following two items:
3333
* element_name_index,

0 commit comments

Comments
 (0)