Skip to content

Commit

Permalink
Restructure jdk directory; add README
Browse files Browse the repository at this point in the history
  • Loading branch information
gharrma committed May 22, 2018
1 parent 6537d12 commit 314c318
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jdk/openjdk-7-src.zip filter=lfs diff=lfs merge=lfs -text
jdk/src.zip filter=lfs diff=lfs merge=lfs -text
3 changes: 2 additions & 1 deletion jdk/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
openjdk-7-src/
src/
src.orig/
out/
4 changes: 2 additions & 2 deletions jdk/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MAIN = Main
PLC := ../bin/polyllvmc
JDK7 ?= /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
JDK_SRC := openjdk-7-src
JDK_SRC := src
PATCHES := patches
OUT := out

Expand Down Expand Up @@ -82,6 +82,6 @@ $(OUT)/classes/cstamp: | $(JDK_SRC)
@date > $@

clean:
rm -rf $(OUT) $(MAIN).binary $(JDK_SRC)
rm -rf $(OUT) $(MAIN).binary $(JDK_SRC) $(JDK_SRC).orig

.PHONY: all
21 changes: 21 additions & 0 deletions jdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
JDK
===

This directory contains source code for OpenJDK 7, and a build system for compiling the JDK with PolyLLVM to produce a shared library.

The OpenJDK codebase is available directly from the [openjdk](http://openjdk.java.net/guide/repositories.html#clone) website, or from one of several git clones such as [this one](https://github.com/dmlloyd/openjdk). However, many JDK Java source files are script-generated, and the build system for JDK 7 is notoriously difficult to configure. So for convenience we track a zip file that contains all JDK sources, prebuilt. This zip file was obtained from [here](https://sourceforge.net/projects/jdk7src/).

Building
--------

The Makefile in this directory will:
(1) Extract JDK source files from the tracked zip file.
(2) Apply PolyLLVM-specific patches to work around a few unsupported features such as reflection and threads. These patches should be removed as the corresponding features are implemented.
(3) Use PolyLLVM to compile the JDK Java source files down to LLVM IR.
(4) Use clang to compile LLVM IR down to object files.
(5) Use clang to link object files from the JDK into a shared library.

Notes
-----

- In addition to direct source patches, there is also a file called `jdk-method-filter.txt`, which PolyLLVM uses to filter out about a dozen methods and field initializers that cause problems due to differences between PolyLLVM and javac. The file has a comment for each method explaining why the method causes issues. This takes advantage of Polyglot's `-method-filter` flag.
2 changes: 1 addition & 1 deletion jdk/make-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ if [ $# -eq 0 ]; then
exit 1
fi

SRC=openjdk-7-src
SRC=src

set -e
mkdir -p `dirname patches/"$1"`
Expand Down
8 changes: 4 additions & 4 deletions jdk/patches/java/io/BufferedInputStream.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--- openjdk-7-src.orig/java/io/BufferedInputStream.java 2013-01-04 14:04:02.000000000 -0500
+++ openjdk-7-src/java/io/BufferedInputStream.java 2018-05-13 17:23:39.000000000 -0400
--- src.orig/java/io/BufferedInputStream.java 2013-01-04 14:04:02.000000000 -0500
+++ src/java/io/BufferedInputStream.java 2018-05-13 17:23:39.000000000 -0400
@@ -59,16 +59,7 @@
*/
protected volatile byte buf[];

- /**
- * Atomic updater to provide compareAndSet for buf. This is
- * necessary because closes can be asynchronous. We use nullness
Expand All @@ -15,7 +15,7 @@
- AtomicReferenceFieldUpdater.newUpdater
- (BufferedInputStream.class, byte[].class, "buf");
+ // Modified for PolyLLVM.

/**
* The index one greater than the index of the last valid byte in
@@ -221,14 +212,7 @@
Expand Down
8 changes: 4 additions & 4 deletions jdk/patches/java/io/FileInputStream.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--- openjdk-7-src.orig/java/io/FileInputStream.java 2013-01-04 14:04:02.000000000 -0500
+++ openjdk-7-src/java/io/FileInputStream.java 2018-05-13 17:45:35.000000000 -0400
--- src.orig/java/io/FileInputStream.java 2013-01-04 14:04:02.000000000 -0500
+++ src/java/io/FileInputStream.java 2018-05-13 17:45:35.000000000 -0400
@@ -56,13 +56,8 @@
private final Object closeLock = new Object();
private volatile boolean closed = false;

- private static final ThreadLocal<Boolean> runningFinalize =
- new ThreadLocal<>();
-
Expand All @@ -14,7 +14,7 @@
- return val.booleanValue();
return false;
}

@@ -397,12 +392,8 @@
* stream is still using it. If the user directly invokes
* close() then the FileDescriptor is also released.
Expand Down
12 changes: 6 additions & 6 deletions jdk/patches/java/lang/Class.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- openjdk-7-src.orig/java/lang/Class.java 2013-01-04 14:04:02.000000000 -0500
+++ openjdk-7-src/java/lang/Class.java 2018-05-12 20:21:23.000000000 -0400
--- src.orig/java/lang/Class.java 2013-01-04 14:04:02.000000000 -0500
+++ src/java/lang/Class.java 2018-05-12 20:21:23.000000000 -0400
@@ -183,7 +183,10 @@
*/
public static Class<?> forName(String className)
Expand All @@ -10,8 +10,8 @@
+ c.name = className;
+ return c;
}


@@ -2154,7 +2157,15 @@
* Return the Virtual Machine's Class object for the named
* primitive type.
Expand All @@ -26,6 +26,6 @@
+ throw new RuntimeException(e);
+ }
+ }


/*
10 changes: 5 additions & 5 deletions jdk/patches/java/lang/System.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
--- openjdk-7-src.orig/java/lang/System.java 2013-01-04 14:04:02.000000000 -0500
+++ openjdk-7-src/java/lang/System.java 2018-05-12 20:20:42.000000000 -0400
--- src.orig/java/lang/System.java 2013-01-04 14:04:02.000000000 -0500
+++ src/java/lang/System.java 2018-05-12 20:20:42.000000000 -0400
@@ -75,7 +75,8 @@
* corresponds to keyboard input or another input source specified by
* the host environment or user.
*/
- public final static InputStream in = null;
+ // Modified for PolyLLVM.
+ public final static InputStream in = new BufferedInputStream(new FileInputStream(FileDescriptor.in));

/**
* The "standard" output stream. This stream is already
@@ -102,7 +103,8 @@
Expand All @@ -17,7 +17,7 @@
- public final static PrintStream out = null;
+ // Modified for PolyLLVM.
+ public final static PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out), 128), true);

/**
* The "standard" error output stream. This stream is already
@@ -116,7 +118,8 @@
Expand All @@ -27,6 +27,6 @@
- public final static PrintStream err = null;
+ // Modified for PolyLLVM.
+ public final static PrintStream err = new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err), 128), true);

/* The security manager for the system.
*/
12 changes: 6 additions & 6 deletions jdk/patches/java/util/HashTable.patch
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
--- openjdk-7-src.orig/java/util/HashTable.java 2013-01-04 14:04:08.000000000 -0500
+++ openjdk-7-src/java/util/HashTable.java 2018-05-12 20:52:05.000000000 -0400
--- src.orig/java/util/HashTable.java 2013-01-04 14:04:08.000000000 -0500
+++ src/java/util/HashTable.java 2018-05-12 20:52:05.000000000 -0400
@@ -218,32 +218,12 @@
*/
transient boolean useAltHashing;

- // Unsafe mechanics
- /**
- * Unsafe utilities
Expand Down Expand Up @@ -32,17 +32,17 @@
*/
- transient final int hashSeed = sun.misc.Hashing.randomHashSeed(this);
+ transient int hashSeed = sun.misc.Hashing.randomHashSeed(this);

private int hash(Object k) {
if (useAltHashing) {
@@ -1000,8 +980,8 @@
s.defaultReadObject();

// set hashSeed
- UNSAFE.putIntVolatile(this, HASHSEED_OFFSET,
- sun.misc.Hashing.randomHashSeed(this));
+ // Modified for PolyLLVM.
+ this.hashSeed = sun.misc.Hashing.randomHashSeed(this);

// Read the original length of the array and number of elements
int origlength = s.readInt();
8 changes: 4 additions & 4 deletions jdk/patches/java/util/concurrent/atomic/AtomicInteger.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
--- openjdk-7-src.orig/java/util/concurrent/atomic/AtomicInteger.java 2013-01-04 14:04:10.000000000 -0500
+++ openjdk-7-src/java/util/concurrent/atomic/AtomicInteger.java 2018-05-16 12:29:53.000000000 -0400
--- src.orig/java/util/concurrent/atomic/AtomicInteger.java 2013-01-04 14:04:10.000000000 -0500
+++ src/java/util/concurrent/atomic/AtomicInteger.java 2018-05-16 12:29:53.000000000 -0400
@@ -57,10 +57,8 @@
private static final long valueOffset;

static {
- try {
- valueOffset = unsafe.objectFieldOffset
Expand All @@ -11,5 +11,5 @@
+ // Modified for PolyLLVM until we have reflection.
+ valueOffset = 16;
}

private volatile int value;
6 changes: 3 additions & 3 deletions jdk/patches/sun/misc/Hashing.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
--- openjdk-7-src.orig/sun/misc/Hashing.java 2013-01-04 14:04:42.000000000 -0500
+++ openjdk-7-src/sun/misc/Hashing.java 2018-05-12 21:02:09.000000000 -0400
--- src.orig/sun/misc/Hashing.java 2013-01-04 14:04:42.000000000 -0500
+++ src/sun/misc/Hashing.java 2018-05-12 21:02:09.000000000 -0400
@@ -257,12 +257,13 @@
// not practically reversible.
int hashing_seed[] = {
Expand All @@ -18,5 +18,5 @@
+ // (int) (System.nanoTime() >>> 5), // resolution is poor
+ // (int) (Runtime.getRuntime().freeMemory() >>> 4) // alloc min
};

seed = murmur3_32(hashing_seed);
File renamed without changes.

0 comments on commit 314c318

Please sign in to comment.