N expr(N n, Expr expr) {
15 | return super.expr(n, expr);
16 | }
17 |
18 | @Override
19 | public void prettyPrint(CodeWriter w, PrettyPrinter pp) {
20 | w.write("synchronized_enter(");
21 | expr.prettyPrint(w, pp);
22 | w.write(")");
23 | }
24 |
25 | @Override
26 | public String toString() {
27 | return "synchronized_enter(" + expr.toString() + ");";
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/compiler/src/jlang/ast/SynchronizedExit.java:
--------------------------------------------------------------------------------
1 | package jlang.ast;
2 |
3 | import polyglot.ast.Expr;
4 | import polyglot.ast.Stmt;
5 |
6 | public interface SynchronizedExit extends Stmt {
7 | Expr expr();
8 | }
9 |
--------------------------------------------------------------------------------
/compiler/src/jlang/ast/SynchronizedExit_c.java:
--------------------------------------------------------------------------------
1 | package jlang.ast;
2 |
3 | import polyglot.ast.Expr;
4 | import polyglot.ast.Ext;
5 | import polyglot.util.CodeWriter;
6 | import polyglot.util.Position;
7 | import polyglot.visit.PrettyPrinter;
8 |
9 | public class SynchronizedExit_c extends AbstractSynchronized implements SynchronizedExit {
10 |
11 | SynchronizedExit_c(Position pos, Expr expr, Ext ext) {
12 | super(pos, expr, ext);
13 | }
14 |
15 | @Override
16 | public void prettyPrint(CodeWriter w, PrettyPrinter pp) {
17 | w.write("synchronized_exit(");
18 | expr.prettyPrint(w, pp);
19 | w.write(")");
20 | }
21 |
22 | @Override
23 | public String toString() {
24 | return "synchronized_exit(" + expr.toString() + ");";
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/compiler/src/jlang/ast/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | AST nodes for the JLang language extension.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangAddressOfExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 |
7 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef;
8 |
9 | import jlang.ast.AddressOf;
10 | import jlang.ast.JLangExt;
11 | import jlang.visit.LLVMTranslator;
12 |
13 | public class JLangAddressOfExt extends JLangExt {
14 |
15 | @Override
16 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) {
17 | AddressOf n = (AddressOf) node();
18 | LLVMValueRef ptr = lang().translateAsLValue(n.expr(), v);
19 | v.addTranslation(n, ptr);
20 | return super.leaveTranslateLLVM(v);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangAnnotationElemExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import jlang.ast.JLangExt;
6 | import jlang.visit.LLVMTranslator;
7 | import polyglot.ast.Node;
8 |
9 | public class JLangAnnotationElemExt extends JLangExt {
10 |
11 | @Override
12 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) {
13 | // Do not recurse into annotations, since there may actually be
14 | // expressions inside, and we don't want to translate them.
15 | // E.g., the annotation @Target({FIELD, METHOD}) contains a list
16 | // of enum values, but they should not appear in LLVM IR.
17 | return node();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangAssertExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Assert;
6 | import polyglot.ast.Expr;
7 | import polyglot.ast.Node;
8 | import polyglot.main.Options;
9 | import polyglot.util.InternalCompilerError;
10 | import polyglot.util.Position;
11 |
12 | import java.util.Collections;
13 | import java.util.List;
14 |
15 | import jlang.ast.JLangExt;
16 | import jlang.visit.DesugarLocally;
17 | import jlang.visit.LLVMTranslator;
18 |
19 | public class JLangAssertExt extends JLangExt {
20 |
21 | @Override
22 | public Node leaveTranslateLLVM(LLVMTranslator v) {
23 | throw new InternalCompilerError("Assert statements should have been desugared");
24 | }
25 |
26 | @Override
27 | public Node desugar(DesugarLocally v) {
28 | Assert n = (Assert) node();
29 | Position pos = n.position();
30 |
31 | if (!Options.global.assertions) {
32 | // Assertions are disabled.
33 | return v.nf.Empty(pos);
34 | }
35 |
36 | List args = n.errorMessage() != null
37 | ? Collections.singletonList(n.errorMessage())
38 | : Collections.emptyList();
39 |
40 | return v.tnf.If(v.tnf.Not(n.cond()), v.tnf.Throw(pos, v.ts.AssertionError(), args));
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangBooleanLitExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.BooleanLit;
6 | import polyglot.ast.Node;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import static org.bytedeco.javacpp.LLVM.*;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | public class JLangBooleanLitExt extends JLangExt {
15 | private static final long serialVersionUID = SerialVersionUID.generate();
16 |
17 | @Override
18 | public Node leaveTranslateLLVM(LLVMTranslator v) {
19 | BooleanLit n = (BooleanLit) node();
20 | LLVMTypeRef type = v.utils.toLL(n.type());
21 | LLVMValueRef val = LLVMConstInt(type, n.value() ? 1 : 0, /*sign-extend*/ 0);
22 | v.addTranslation(node(), val);
23 | return super.leaveTranslateLLVM(v);
24 | }
25 |
26 | @Override
27 | public void translateLLVMConditional(LLVMTranslator v,
28 | LLVMBasicBlockRef trueBlock,
29 | LLVMBasicBlockRef falseBlock) {
30 | BooleanLit n = (BooleanLit) node();
31 | LLVMBuildBr(v.builder, n.value() ? trueBlock : falseBlock);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangBranchExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Branch;
6 | import polyglot.ast.Node;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import static org.bytedeco.javacpp.LLVM.LLVMBuildBr;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | public class JLangBranchExt extends JLangExt {
15 | private static final long serialVersionUID = SerialVersionUID.generate();
16 |
17 | @Override
18 | public Node leaveTranslateLLVM(LLVMTranslator v) {
19 | Branch n = (Branch) node();
20 |
21 | LLVMTranslator.ControlTransferLoc loc = n.kind() == Branch.CONTINUE
22 | ? v.getContinueLoc(n.label())
23 | : v.getBreakLoc(n.label());
24 |
25 | // If we are within an exception frame, we may need to detour through finally blocks first.
26 | v.buildFinallyBlockChain(loc.getTryCatchNestingLevel());
27 |
28 | LLVMBuildBr(v.builder, loc.getBlock());
29 |
30 | return super.leaveTranslateLLVM(v);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangCharLitExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.CharLit;
6 | import polyglot.ast.Node;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import static org.bytedeco.javacpp.LLVM.*;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | public class JLangCharLitExt extends JLangExt {
15 | private static final long serialVersionUID = SerialVersionUID.generate();
16 |
17 | @Override
18 | public Node leaveTranslateLLVM(LLVMTranslator v) {
19 | CharLit n = (CharLit) node();
20 | LLVMTypeRef type = v.utils.toLL(n.type());
21 | LLVMValueRef val = LLVMConstInt(type, n.value(), /*sign-extend*/ 0);
22 | v.addTranslation(n, val);
23 | return super.leaveTranslateLLVM(v);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangConstructorCallExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.ConstructorCall;
6 | import polyglot.ast.Node;
7 | import polyglot.util.InternalCompilerError;
8 | import polyglot.util.SerialVersionUID;
9 |
10 | import static org.bytedeco.javacpp.LLVM.LLVMGetParam;
11 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef;
12 |
13 | import jlang.visit.LLVMTranslator;
14 |
15 | public class JLangConstructorCallExt extends JLangProcedureCallExt {
16 | private static final long serialVersionUID = SerialVersionUID.generate();
17 |
18 | @Override
19 | public Node leaveTranslateLLVM(LLVMTranslator v) {
20 | if (node().qualifier() != null)
21 | throw new InternalCompilerError("Qualified ctor call should have been desugared");
22 |
23 | // Most of the translation happens in this super call.
24 | return super.leaveTranslateLLVM(v);
25 | }
26 |
27 | @Override
28 | protected LLVMValueRef buildReceiverArg(LLVMTranslator v) {
29 | return LLVMGetParam(v.currFn(), 0);
30 | }
31 |
32 | @Override
33 | public ConstructorCall node() {
34 | return (ConstructorCall) super.node();
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangDesugaredNodeExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import jlang.ast.JLangExt;
6 | import jlang.visit.LLVMTranslator;
7 | import polyglot.ast.Node;
8 | import polyglot.util.InternalCompilerError;
9 |
10 | public class JLangDesugaredNodeExt extends JLangExt {
11 | private static final String errorMsg =
12 | "This node should be desugared before translating to LLVM IR";
13 |
14 | @Override
15 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) {
16 | throw new InternalCompilerError(errorMsg + ": " + node().getClass());
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangEseqExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 |
7 | import static org.bytedeco.javacpp.LLVM.LLVMBasicBlockRef;
8 | import static org.bytedeco.javacpp.LLVM.LLVMValueRef;
9 |
10 | import jlang.ast.ESeq;
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | public class JLangEseqExt extends JLangExt {
15 |
16 | @Override
17 | public Node leaveTranslateLLVM(LLVMTranslator v) {
18 | ESeq n = (ESeq) node();
19 | v.addTranslation(n, v.getTranslation(n.expr()));
20 | return super.leaveTranslateLLVM(v);
21 | }
22 |
23 | @Override
24 | public void translateLLVMConditional(
25 | LLVMTranslator v, LLVMBasicBlockRef trueBlock, LLVMBasicBlockRef falseBlock) {
26 | ESeq n = (ESeq) node();
27 | n.visitList(n.statements(), v);
28 | lang().translateLLVMConditional(n.expr(), v, trueBlock, falseBlock);
29 | }
30 |
31 | @Override
32 | public LLVMValueRef translateAsLValue(LLVMTranslator v) {
33 | ESeq n = (ESeq) node();
34 | n.visitList(n.statements(), v);
35 | return lang().translateAsLValue(n.expr(), v);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangFloatLitExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.FloatLit;
6 | import polyglot.ast.Node;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import static org.bytedeco.javacpp.LLVM.LLVMConstReal;
10 | import static org.bytedeco.javacpp.LLVM.LLVMTypeRef;
11 |
12 | import jlang.ast.JLangExt;
13 | import jlang.visit.LLVMTranslator;
14 |
15 | public class JLangFloatLitExt extends JLangExt {
16 | private static final long serialVersionUID = SerialVersionUID.generate();
17 |
18 | @Override
19 | public Node leaveTranslateLLVM(LLVMTranslator v) {
20 | FloatLit n = (FloatLit) node();
21 | LLVMTypeRef type = v.utils.toLL(n.type());
22 | v.addTranslation(n, LLVMConstReal(type, n.value()));
23 | return super.leaveTranslateLLVM(v);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangIfExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.If;
6 | import polyglot.ast.Node;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import java.lang.Override;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | import static org.bytedeco.javacpp.LLVM.*;
15 |
16 | public class JLangIfExt extends JLangExt {
17 | private static final long serialVersionUID = SerialVersionUID.generate();
18 |
19 | @Override
20 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) {
21 | If n = (If) node();
22 | LLVMBasicBlockRef ifEnd = v.utils.buildBlock("if.end");
23 | LLVMBasicBlockRef ifTrue = v.utils.buildBlock("if.true");
24 | LLVMBasicBlockRef ifFalse = n.alternative() != null
25 | ? v.utils.buildBlock("if.false")
26 | : ifEnd;
27 |
28 | lang().translateLLVMConditional(n.cond(), v, ifTrue, ifFalse);
29 |
30 | LLVMPositionBuilderAtEnd(v.builder, ifTrue);
31 | n.visitChild(n.consequent(), v);
32 | v.utils.branchUnlessTerminated(ifEnd);
33 |
34 | if (n.alternative() != null) {
35 | LLVMPositionBuilderAtEnd(v.builder, ifFalse);
36 | n.visitChild(n.alternative(), v);
37 | v.utils.branchUnlessTerminated(ifEnd);
38 | }
39 |
40 | LLVMPositionBuilderAtEnd(v.builder, ifEnd);
41 | return n;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangInitializerExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import jlang.ast.JLangExt;
6 | import jlang.visit.LLVMTranslator;
7 | import polyglot.ast.Node;
8 | import polyglot.util.SerialVersionUID;
9 |
10 | public class JLangInitializerExt extends JLangExt {
11 | private static final long serialVersionUID = SerialVersionUID.generate();
12 |
13 | @Override
14 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) {
15 | // Instance initializers and static initializers are desugared
16 | // into standalone functions that are called when necessary.
17 | return node();
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangInstanceofExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Instanceof;
6 | import polyglot.ast.Node;
7 | import polyglot.types.ReferenceType;
8 | import polyglot.util.SerialVersionUID;
9 |
10 | import java.lang.Override;
11 |
12 | import jlang.ast.JLangExt;
13 | import jlang.visit.LLVMTranslator;
14 |
15 | import static org.bytedeco.javacpp.LLVM.*;
16 |
17 | public class JLangInstanceofExt extends JLangExt {
18 | private static final long serialVersionUID = SerialVersionUID.generate();
19 |
20 | @Override
21 | public Node leaveTranslateLLVM(LLVMTranslator v) {
22 | Instanceof n = (Instanceof) node();
23 | LLVMValueRef obj = v.getTranslation(n.expr());
24 | ReferenceType rt = n.compareType().type().toReference();
25 | LLVMValueRef compTypeIdVar = v.classObjs.toTypeIdentity(rt);
26 | LLVMTypeRef bytePtrTy = v.utils.ptrTypeRef(v.utils.intType(8));
27 | LLVMTypeRef objTy = v.utils.toLL(v.ts.Object());
28 | LLVMValueRef objBitcast = LLVMBuildBitCast(v.builder, obj, objTy, "cast.obj");
29 | LLVMTypeRef funcType = v.utils.functionType(v.utils.intType(1), objTy, bytePtrTy);
30 | LLVMValueRef function = v.utils.getFunction("InstanceOf", funcType);
31 | LLVMValueRef res = v.utils.buildFunCall(function, objBitcast, compTypeIdVar);
32 | v.addTranslation(n, res);
33 | return super.leaveTranslateLLVM(v);
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangIntLitExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.IntLit;
6 | import polyglot.ast.Node;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import static org.bytedeco.javacpp.LLVM.*;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | public class JLangIntLitExt extends JLangExt {
15 | private static final long serialVersionUID = SerialVersionUID.generate();
16 |
17 | @Override
18 | public Node leaveTranslateLLVM(LLVMTranslator v) {
19 | IntLit n = (IntLit) node();
20 | assert n.type().isLongOrLess();
21 | LLVMTypeRef type = v.utils.toLL(n.type());
22 | LLVMValueRef res = LLVMConstInt(type, n.value(), /*sign-extend*/ 0);
23 | v.addTranslation(n, res);
24 | return super.leaveTranslateLLVM(v);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangLoadExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 |
7 | import java.lang.Override;
8 |
9 | import jlang.ast.Load;
10 | import jlang.ast.JLangExt;
11 | import jlang.visit.LLVMTranslator;
12 |
13 | import static org.bytedeco.javacpp.LLVM.*;
14 |
15 | public class JLangLoadExt extends JLangExt {
16 |
17 | @Override
18 | public Node leaveTranslateLLVM(LLVMTranslator v) {
19 | Load n = (Load) node();
20 | LLVMValueRef ptr = v.getTranslation(n.expr());
21 | LLVMValueRef val = LLVMBuildLoad(v.builder, ptr, "load");
22 | v.addTranslation(n, val);
23 | return super.leaveTranslateLLVM(v);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangNullLitExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 | import polyglot.ast.NullLit;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import static org.bytedeco.javacpp.LLVM.LLVMConstNull;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | public class JLangNullLitExt extends JLangExt {
15 | private static final long serialVersionUID = SerialVersionUID.generate();
16 |
17 | @Override
18 | public Node leaveTranslateLLVM(LLVMTranslator v) {
19 | NullLit n = (NullLit) node();
20 | v.addTranslation(n, LLVMConstNull(v.utils.toLL(n.type())));
21 | return super.leaveTranslateLLVM(v);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangSpecialExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 | import polyglot.ast.Special;
7 | import polyglot.util.InternalCompilerError;
8 | import polyglot.util.SerialVersionUID;
9 |
10 | import static org.bytedeco.javacpp.LLVM.*;
11 |
12 | import jlang.ast.JLangExt;
13 | import jlang.visit.LLVMTranslator;
14 |
15 | public class JLangSpecialExt extends JLangExt {
16 | private static final long serialVersionUID = SerialVersionUID.generate();
17 |
18 | @Override
19 | public Node leaveTranslateLLVM(LLVMTranslator v) {
20 | Special n = (Special) node();
21 |
22 | if (n.qualifier() != null)
23 | throw new InternalCompilerError(
24 | "Qualified this should have been desugared by the DesugarInnerClasses visitor");
25 | if (n.kind().equals(Special.SUPER))
26 | throw new InternalCompilerError(
27 | "super should have been desugared by the DesugarInnerClasses visitor");
28 | assert n.kind().equals(Special.THIS);
29 |
30 | v.addTranslation(n, LLVMGetParam(v.currFn(), 0));
31 | return super.leaveTranslateLLVM(v);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangSynchronizedEnterExt.java:
--------------------------------------------------------------------------------
1 | package jlang.extension;
2 |
3 | import jlang.ast.JLangExt;
4 | import jlang.ast.SynchronizedEnter;
5 | import jlang.util.Constants;
6 | import jlang.visit.LLVMTranslator;
7 | import org.bytedeco.javacpp.LLVM.LLVMTypeRef;
8 | import org.bytedeco.javacpp.LLVM.LLVMValueRef;
9 | import polyglot.ast.Node;
10 |
11 | import static jlang.extension.JLangSynchronizedExt.buildMonitorFunc;
12 |
13 | public class JLangSynchronizedEnterExt extends JLangExt {
14 |
15 | @Override
16 | public Node leaveTranslateLLVM(LLVMTranslator v) {
17 | SynchronizedEnter n = (SynchronizedEnter) node();
18 |
19 | LLVMValueRef obj = v.getTranslation(n.expr());
20 |
21 | buildMonitorFunc(v, Constants.MONITOR_ENTER, obj);
22 |
23 | return n;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangSynchronizedExitExt.java:
--------------------------------------------------------------------------------
1 | package jlang.extension;
2 |
3 | import jlang.ast.JLangExt;
4 | import jlang.ast.SynchronizedEnter;
5 | import jlang.ast.SynchronizedExit;
6 | import jlang.util.Constants;
7 | import jlang.visit.LLVMTranslator;
8 | import org.bytedeco.javacpp.LLVM.LLVMValueRef;
9 | import polyglot.ast.Node;
10 |
11 | import static jlang.extension.JLangSynchronizedExt.buildMonitorFunc;
12 |
13 | public class JLangSynchronizedExitExt extends JLangExt {
14 |
15 | @Override
16 | public Node leaveTranslateLLVM(LLVMTranslator v) {
17 | SynchronizedExit n = (SynchronizedExit) node();
18 |
19 | LLVMValueRef obj = v.getTranslation(n.expr());
20 |
21 | buildMonitorFunc(v, Constants.MONITOR_EXIT, obj);
22 |
23 | return n;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangThrowExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 | import polyglot.ast.Throw;
7 |
8 | import java.lang.Override;
9 |
10 | import jlang.ast.JLangExt;
11 | import jlang.util.Constants;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | import static org.bytedeco.javacpp.LLVM.*;
15 |
16 | public class JLangThrowExt extends JLangExt {
17 |
18 | @Override
19 | public Node leaveTranslateLLVM(LLVMTranslator v) {
20 | Throw n = (Throw) node();
21 | LLVMValueRef createExnFun = v.utils.getFunction(Constants.CREATE_EXCEPTION,
22 | v.utils.functionType(v.utils.i8Ptr(), v.utils.i8Ptr()));
23 | LLVMValueRef throwExnFunc = v.utils.getFunction(Constants.THROW_EXCEPTION,
24 | v.utils.functionType(LLVMVoidTypeInContext(v.context), v.utils.i8Ptr()));
25 | LLVMValueRef cast = LLVMBuildBitCast(
26 | v.builder, v.getTranslation(n.expr()), v.utils.i8Ptr(), "cast");
27 | LLVMValueRef exn = v.utils.buildFunCall(createExnFun, cast);
28 | v.utils.buildProcCall(throwExnFunc, exn);
29 | LLVMBuildUnreachable(v.builder);
30 | return super.leaveTranslateLLVM(v);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/JLangWhileExt.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.extension;
4 |
5 | import polyglot.ast.Node;
6 | import polyglot.ast.While;
7 | import polyglot.util.SerialVersionUID;
8 |
9 | import java.lang.Override;
10 |
11 | import jlang.ast.JLangExt;
12 | import jlang.visit.LLVMTranslator;
13 |
14 | import static org.bytedeco.javacpp.LLVM.*;
15 |
16 | public class JLangWhileExt extends JLangExt {
17 | private static final long serialVersionUID = SerialVersionUID.generate();
18 |
19 | @Override
20 | public Node overrideTranslateLLVM(Node parent, LLVMTranslator v) {
21 | While n = (While) node();
22 |
23 | LLVMBasicBlockRef cond = v.utils.buildBlock("while.cond");
24 | LLVMBasicBlockRef body = v.utils.buildBlock("while.body");
25 | LLVMBasicBlockRef end = v.utils.buildBlock("while.end");
26 |
27 | v.pushLoop(cond, end);
28 |
29 | // Conditional.
30 | LLVMBuildBr(v.builder, cond);
31 | LLVMPositionBuilderAtEnd(v.builder, cond);
32 | lang().translateLLVMConditional(n.cond(), v, body, end);
33 |
34 | // Body.
35 | LLVMPositionBuilderAtEnd(v.builder, body);
36 | n.visitChild(n.body(), v);
37 | v.utils.branchUnlessTerminated(cond);
38 |
39 | LLVMPositionBuilderAtEnd(v.builder, end);
40 | v.popLoop();
41 | return n;
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/compiler/src/jlang/extension/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | AST extensions and delegates for the JLang language extension.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/compiler/src/jlang/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | JLang language extension.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/compiler/src/jlang/structures/DispatchVector.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.structures;
4 |
5 | import org.bytedeco.javacpp.LLVM.LLVMTypeRef;
6 | import org.bytedeco.javacpp.LLVM.LLVMValueRef;
7 | import polyglot.types.MethodInstance;
8 | import polyglot.types.ReferenceType;
9 |
10 | /**
11 | * Defines the layout of a dispatch vector in terms of LLVM IR.
12 | * Translations wishing to access elements in a dispatch vector at
13 | * runtime should go through this interface.
14 | */
15 | public interface DispatchVector {
16 |
17 | /** Returns an LLVM type representing the dispatch vector layout. */
18 | LLVMTypeRef structTypeRef(ReferenceType rt);
19 |
20 | /** Initializes the dispatch vector for a specific concrete class. */
21 | void initializeDispatchVectorFor(ReferenceType rt);
22 |
23 | /** Returns a pointer to the dispatch vector for a specific concrete class. */
24 | LLVMValueRef getDispatchVectorFor(ReferenceType rt);
25 |
26 | /** Returns a pointer to the specified method in a dispatch vector. */
27 | LLVMValueRef buildFuncElementPtr(LLVMValueRef dvPtr, ReferenceType rt, MethodInstance mi);
28 | }
29 |
--------------------------------------------------------------------------------
/compiler/src/jlang/test/TestAll.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.test;
4 |
5 | import org.junit.runner.RunWith;
6 | import org.junit.runners.Suite;
7 | import org.junit.runners.Suite.SuiteClasses;
8 |
9 | @RunWith(Suite.class)
10 | @SuiteClasses({ TestFunctional.class })
11 |
12 | public class TestAll {
13 | }
14 |
--------------------------------------------------------------------------------
/compiler/src/jlang/types/JLangClassFileLazyClassInitializer.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.types;
4 |
5 | import polyglot.ext.jl5.types.reflect.JL5ClassFileLazyClassInitializer;
6 | import polyglot.types.ClassType;
7 | import polyglot.types.MethodInstance;
8 | import polyglot.types.reflect.ClassFile;
9 | import polyglot.types.reflect.Method;
10 |
11 | public class JLangClassFileLazyClassInitializer extends JL5ClassFileLazyClassInitializer {
12 |
13 | JLangTypeSystem ts;
14 |
15 | public JLangClassFileLazyClassInitializer(ClassFile file, JLangTypeSystem ts) {
16 | super(file, ts);
17 | this.ts = ts;
18 | }
19 |
20 | @Override
21 | protected MethodInstance methodInstance(Method m, ClassType ct) {
22 | MethodInstance mi = super.methodInstance(m, ct);
23 | JLangParsedClassType_c pct = (JLangParsedClassType_c) ct;
24 | if (pct.isNewMethod(mi)) {
25 | return mi;
26 | } else {
27 | return null;
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/compiler/src/jlang/types/JLangLocalInstance.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.types;
4 |
5 | import polyglot.ext.jl5.types.JL5LocalInstance;
6 |
7 | public interface JLangLocalInstance extends JL5LocalInstance {
8 |
9 | /**
10 | * Whether this is a compiler-generated variable that should not be
11 | * visible to the user when debugging.
12 | */
13 | boolean isTemp();
14 |
15 | /** Whether this variable is in SSA form. */
16 | boolean isSSA();
17 | }
18 |
--------------------------------------------------------------------------------
/compiler/src/jlang/types/JLangLocalInstance_c.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.types;
4 |
5 | import polyglot.ext.jl5.types.JL5LocalInstance_c;
6 | import polyglot.types.Flags;
7 | import polyglot.types.Type;
8 | import polyglot.types.TypeSystem;
9 | import polyglot.util.Position;
10 |
11 | public class JLangLocalInstance_c
12 | extends JL5LocalInstance_c
13 | implements JLangLocalInstance {
14 | private final boolean isTemp, isSSA;
15 |
16 | public JLangLocalInstance_c(
17 | TypeSystem ts, Position pos, Flags flags, Type type, String name,
18 | boolean isTemp, boolean isSSA) {
19 | super(ts, pos, flags, type, name);
20 | this.isTemp = isTemp;
21 | this.isSSA = isSSA;
22 | }
23 |
24 | @Override
25 | public boolean isTemp() {
26 | return isTemp;
27 | }
28 |
29 | @Override
30 | public boolean isSSA() {
31 | return isSSA;
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/compiler/src/jlang/types/JLangTypeSystem.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.types;
4 |
5 | import polyglot.ext.jl5.types.JL5MethodInstance;
6 | import polyglot.ext.jl5.types.JL5Subst;
7 | import polyglot.ext.jl7.types.JL7TypeSystem;
8 | import polyglot.types.ClassType;
9 | import polyglot.types.Flags;
10 | import polyglot.types.ParsedClassType;
11 | import polyglot.types.Type;
12 | import polyglot.util.Position;
13 |
14 | public interface JLangTypeSystem extends JL7TypeSystem {
15 |
16 | ParsedClassType ArrayObject();
17 |
18 | ClassType RuntimeHelper();
19 |
20 | @Override
21 | JLangLocalInstance localInstance(Position pos, Flags flags, Type type, String name);
22 |
23 | /**
24 | * Creates a local instance with the option of making it a temp variable, which
25 | * is hidden from the user when debugging.
26 | */
27 | JLangLocalInstance localInstance(
28 | Position pos, Flags flags, Type type, String name, boolean isTemp, boolean isSSA);
29 |
30 | SubstMethodInstance substMethodInstance(JL5MethodInstance postSubst,
31 | JL5MethodInstance preSubst, JL5Subst subst);
32 |
33 |
34 | /** Returns whether two types are equal when ignoring generics. */
35 | boolean typeEqualsErased(Type a, Type b);
36 |
37 | /** Returns whether {@code a} is a subtype of {@code b}, ignoring generics. */
38 | boolean isSubtypeErased(Type a, Type b);
39 | }
40 |
--------------------------------------------------------------------------------
/compiler/src/jlang/types/SubstMethodInstance.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.types;
4 |
5 | import polyglot.ext.jl5.types.JL5MethodInstance;
6 | import polyglot.ext.jl5.types.JL5Subst;
7 |
8 | /**
9 | * Represents a Java method whose type parameters have been substituted, but
10 | * also keeps track of information about this substitution. All methods produced
11 | * by type-checking a method call are instances of this type.
12 | *
13 | *
14 | * In Polyglot, type-checking a method call produces the substituted method
15 | * instance, but does not give back the substitution for the method's type
16 | * parameters. This interface provides a workaround to allow for querying about
17 | * the substitution for a method's type parameters in the scenario of a method
18 | * call.
19 | *
20 | */
21 | public interface SubstMethodInstance extends JL5MethodInstance {
22 | /**
23 | * Returns the method before substituting its type parameters. The returned
24 | * value cannot be a {@link SubstMethodInstance}.
25 | */
26 | JL5MethodInstance base();
27 |
28 | /**
29 | * Returns the substitution for the type parameters of the method. If the
30 | * original method is not parameterized, it returns an empty substitution.
31 | */
32 | JL5Subst subst();
33 | }
34 |
--------------------------------------------------------------------------------
/compiler/src/jlang/util/CollectUtils.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.util;
4 |
5 | import java.lang.reflect.Array;
6 | import java.util.List;
7 |
8 | public final class CollectUtils {
9 |
10 | static public T[] toArray(List extends T> l, Class clazz) {
11 | @SuppressWarnings("unchecked")
12 | T[] res = (T[]) Array.newInstance(clazz, l.size());
13 | int idx = 0;
14 | for (T t : l)
15 | res[idx++] = t;
16 | return res;
17 | }
18 |
19 | static public T[] toArray(T head, List extends T> l, Class clazz) {
20 | @SuppressWarnings("unchecked")
21 | T[] res = (T[]) Array.newInstance(clazz, 1 + l.size());
22 | int idx = 0;
23 | res[idx++] = head;
24 | for (T t : l)
25 | res[idx++] = t;
26 | return res;
27 | }
28 |
29 | static public T[] toArray(T t1, T t2, List extends T> l,
30 | Class clazz) {
31 | @SuppressWarnings("unchecked")
32 | T[] res = (T[]) Array.newInstance(clazz, 2 + l.size());
33 | int idx = 0;
34 | res[idx++] = t1;
35 | res[idx++] = t2;
36 | for (T t : l)
37 | res[idx++] = t;
38 | return res;
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/compiler/src/jlang/util/DesugarBarrier.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.util;
4 |
5 | import jlang.JLangScheduler;
6 | import polyglot.frontend.Job;
7 | import polyglot.frontend.goals.Barrier;
8 | import polyglot.frontend.goals.Goal;
9 |
10 | public class DesugarBarrier extends Barrier {
11 |
12 | private final JLangScheduler jlangScheduler;
13 |
14 | public static DesugarBarrier create(JLangScheduler s) {
15 | return new DesugarBarrier(s);
16 | }
17 |
18 | protected DesugarBarrier(JLangScheduler scheduler) {
19 | super(scheduler);
20 | this.jlangScheduler = scheduler;
21 | }
22 |
23 | @Override
24 | public Goal goalForJob(Job job) {
25 | return this.jlangScheduler.LLVMDesugared(job);
26 | }
27 |
28 | }
29 |
--------------------------------------------------------------------------------
/compiler/src/jlang/util/JLangFreshGen.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.util;
4 |
5 | import java.util.HashMap;
6 | import java.util.Map;
7 |
8 | public class JLangFreshGen {
9 |
10 | private static JLangFreshGen instance = null;
11 |
12 | Map prefixMap;
13 |
14 | private JLangFreshGen() {
15 | prefixMap = new HashMap<>();
16 | }
17 |
18 | private static JLangFreshGen instance() {
19 | if (instance == null) {
20 | instance = new JLangFreshGen();
21 | }
22 | return instance;
23 | }
24 |
25 | private String freshString(String string) {
26 | String ret;
27 | if (prefixMap.containsKey(string)) {
28 | ret = string + prefixMap.get(string);
29 | prefixMap.put(string, prefixMap.get(string) + 1);
30 | }
31 | else {
32 | ret = string + "0";
33 | prefixMap.put(string, 1);
34 | }
35 | return ret;
36 | }
37 |
38 | public static String fresh() {
39 | return instance().freshString("fresh");
40 | }
41 |
42 |
43 | }
44 |
--------------------------------------------------------------------------------
/compiler/src/jlang/visit/StringLitFold.java:
--------------------------------------------------------------------------------
1 | package jlang.visit;
2 |
3 | import polyglot.ast.Binary;
4 | import polyglot.ast.Expr;
5 | import polyglot.ast.Node;
6 | import polyglot.ast.NodeFactory;
7 | import polyglot.types.TypeSystem;
8 | import polyglot.util.Position;
9 | import polyglot.visit.NodeVisitor;
10 |
11 | /**
12 | * Created by dantech on 11/4/18.
13 | */
14 | public class StringLitFold extends NodeVisitor {
15 |
16 | protected TypeSystem ts;
17 | protected NodeFactory nf;
18 |
19 | public StringLitFold(TypeSystem ts, NodeFactory nf) {
20 | super(nf.lang());
21 | this.ts = ts;
22 | this.nf = nf;
23 | }
24 |
25 | @Override
26 | public Node leave(Node old, Node n, NodeVisitor v_) {
27 | if (!(n instanceof Expr)) {
28 | return n;
29 | }
30 |
31 | Expr e = (Expr) n;
32 |
33 | if (!lang().isConstant(e, lang())) {
34 | return e;
35 | }
36 |
37 | if (e instanceof Binary) {
38 | Binary b = (Binary) e;
39 |
40 | if (b.operator() == Binary.ADD
41 | && lang().constantValue(b.left(), lang()) instanceof String
42 | && lang().constantValue(b.right(), lang()) instanceof String) {
43 | String lit = (String) lang().constantValue(b, lang());
44 | Position pos = e.position();
45 | return nf.StringLit(pos, lit).type(ts.String());
46 | }
47 | }
48 |
49 | return e;
50 | }
51 |
52 | }
53 |
--------------------------------------------------------------------------------
/compiler/src/jlang/visit/package.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | Visitors for the JLang language extension.
4 |
5 |
6 |
--------------------------------------------------------------------------------
/defs.Darwin:
--------------------------------------------------------------------------------
1 | export SHARED_LIB_EXT := dylib
2 |
3 | # TODO: Ideally would would not need dynamic_lookup here.
4 | export LIBJVM_FLAGS += \
5 | -current_version 1.0.0 -compatibility_version 1.0.0 \
6 | -undefined dynamic_lookup
7 |
8 | # use xcode header search path for macOS 10.15+
9 | export MACOS_FLAGS :=
10 | ifeq ($(shell expr $(shell sw_vers -productVersion) \>= 10.15),1)
11 | MACOS_FLAGS += \
12 | -isysroot $(shell xcrun --show-sdk-path) \
13 | -I/usr/local/include
14 | endif
15 |
16 |
--------------------------------------------------------------------------------
/defs.Linux:
--------------------------------------------------------------------------------
1 | export SHARED_LIB_EXT := so
2 | export JDK7_LIB_PATH := $(JDK7)/jre/lib/amd64
3 | export LIBJVM_FLAGS = $(SHARED_LIB_FLAGS) -Wl,--version-script=linux_version.map
--------------------------------------------------------------------------------
/docs/.gitignore:
--------------------------------------------------------------------------------
1 | _site/
2 |
--------------------------------------------------------------------------------
/docs/README.md:
--------------------------------------------------------------------------------
1 | Making changes to the website
2 | -----------------------------
3 |
4 | Documentation is translated from Markdown to HTML using [Jekyll](http://jekyllrb.com), which is well integrated with Github. To make changes to the website, simply edit a Markdown file and push to master. To preview local changes, install Jekyll and type `jekyll serve`.
5 |
--------------------------------------------------------------------------------
/docs/_config.yml:
--------------------------------------------------------------------------------
1 | kramdown:
2 | input: GFM
3 | hard_wrap: false
4 | project: "JLang"
5 | contact: jlang-users-l@cornell.edu
6 | contact-join: jlang-users-l-request@cornell.edu
7 | update-month: March
8 | update-year: 2020
9 | update-date: 3-1-2020
10 |
11 | github:
12 | url: https://github.com/polyglot-compiler/JLang
13 |
14 |
--------------------------------------------------------------------------------
/docs/contact-us.md:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Contact Us"
3 | layout: subscribe
4 | ---
5 |
6 |
7 | Mailing List
8 | ------------
9 |
10 | There is a mailing list for JLang users and contributors.
11 | This is a great forum for development, design and feature discussions. Use the form below to join the JLang users list!
12 |
13 | To report bugs or monitor in-development improvements, please check the Github issues page.
14 |
15 |
16 |
17 | Contributor Contact
18 | ------------------
19 |
20 | For any questions which can't be addressed in the above methods, please reach out to Drew Zagieboylo or Andrew C. Myers.
21 |
--------------------------------------------------------------------------------
/examples/cup/Makefile.obj:
--------------------------------------------------------------------------------
1 | OUT := out
2 | LL := $(shell find $(OUT)/java_cup/runtime -name "*.ll")
3 | OBJ := $(LL:%.ll=%.o)
4 |
5 | all: $(OBJ)
6 | .PHONY: all
7 |
8 | $(OBJ): %.o: %.ll
9 | @echo "Compiling $<"
10 | @$(CLANG) -Wno-override-module -fPIC -c -o $@ $<
11 |
--------------------------------------------------------------------------------
/examples/cup/bin/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/bin/JFlex.jar
--------------------------------------------------------------------------------
/examples/cup/bin/cup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
3 | export JAVA_HOME="$JDK7"
4 | "$DIR"/Main.o "$@"
5 |
--------------------------------------------------------------------------------
/examples/cup/bin/debug-cup.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
3 | export JAVA_HOME="$JDK7"
4 | gdb "$DIR"/Main.o "$@"
5 |
--------------------------------------------------------------------------------
/examples/cup/bin/java-cup-11.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/bin/java-cup-11.jar
--------------------------------------------------------------------------------
/examples/cup/changelog.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/changelog.txt
--------------------------------------------------------------------------------
/examples/cup/src/java/.gitignore:
--------------------------------------------------------------------------------
1 | #/java_cup/parser.java
2 | #/java_cup/sym.java
3 | #/java_cup/Lexer.java
--------------------------------------------------------------------------------
/examples/cup/src/java/java_cup/assoc.java:
--------------------------------------------------------------------------------
1 | package java_cup;
2 |
3 | /* Defines integers that represent the associativity of terminals
4 | * @version last updated: 7/3/96
5 | * @author Frank Flannery
6 | */
7 |
8 | public class assoc {
9 |
10 | /* various associativities, no_prec being the default value */
11 | public final static int left = 0;
12 | public final static int right = 1;
13 | public final static int nonassoc = 2;
14 | public final static int no_prec = -1;
15 |
16 | }
--------------------------------------------------------------------------------
/examples/cup/src/java/java_cup/internal_error.java:
--------------------------------------------------------------------------------
1 |
2 | package java_cup;
3 |
4 | /** Exception subclass for reporting internal errors in JavaCup. */
5 | public class internal_error extends Exception
6 | {
7 | /** Constructor with a message */
8 | public internal_error(String msg)
9 | {
10 | super(msg);
11 | }
12 |
13 | /** Method called to do a forced error exit on an internal error
14 | for cases when we can't actually throw the exception. */
15 | public void crash()
16 | {
17 | ErrorManager.getManager().emit_fatal("JavaCUP Internal Error Detected: "+getMessage());
18 | printStackTrace();
19 | System.exit(-1);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/examples/cup/src/java/java_cup/runtime/Scanner.java:
--------------------------------------------------------------------------------
1 | package java_cup.runtime;
2 |
3 | /**
4 | * Defines the Scanner interface, which CUP uses in the default
5 | * implementation of lr_parser.scan()
. Integration
6 | * of scanners implementing Scanner
is facilitated.
7 | *
8 | * @version last updated 23-Jul-1999
9 | * @author David MacMahon
10 | */
11 |
12 | /* *************************************************
13 | Interface Scanner
14 |
15 | Declares the next_token() method that should be
16 | implemented by scanners. This method is typically
17 | called by lr_parser.scan(). End-of-file can be
18 | indicated either by returning
19 | new Symbol(lr_parser.EOF_sym())
or
20 | null
.
21 | ***************************************************/
22 | public interface Scanner {
23 | /** Return the next token, or null
on end-of-file. */
24 | public Symbol next_token() throws java.lang.Exception;
25 | }
26 |
--------------------------------------------------------------------------------
/examples/cup/src/java/java_cup/runtime/ScannerBuffer.java:
--------------------------------------------------------------------------------
1 | package java_cup.runtime;
2 |
3 | import java.util.Collections;
4 | import java.util.LinkedList;
5 | import java.util.List;
6 |
7 | public class ScannerBuffer implements Scanner {
8 | private Scanner inner;
9 | private List buffer = new LinkedList();
10 | /**
11 | * Wraps around a custom scanner and stores all so far produced tokens in a buffer
12 | * @param inner the scanner to buffer
13 | */
14 | public ScannerBuffer(Scanner inner){
15 | this.inner=inner;
16 | }
17 | /**
18 | * Read-Only access to the buffered Symbols
19 | * @return an unmodifiable Version of the buffer
20 | */
21 | public List getBuffered() {
22 | return Collections.unmodifiableList(buffer);
23 | }
24 | @Override
25 | public Symbol next_token() throws Exception {
26 | Symbol buffered = inner.next_token();
27 | buffer.add(buffered);
28 | return buffered;
29 | }
30 |
31 | }
32 |
--------------------------------------------------------------------------------
/examples/cup/target/.gitignore:
--------------------------------------------------------------------------------
1 | /classes/
2 | /dist/
--------------------------------------------------------------------------------
/examples/cup/test/example.cup:
--------------------------------------------------------------------------------
1 | import java_cup.runtime.*;
2 |
3 | parser code {:
4 | // Connect this parser to a scanner!
5 | scanner s;
6 | Parser(scanner s){ this.s=s; }
7 | :}
8 |
9 | /* define how to connect to the scanner! */
10 | init with {: s.init(); :};
11 | scan with {: return s.next_token(); :};
12 |
13 | /* Terminals (tokens returned by the scanner). */
14 | terminal SEMI, PLUS, MINUS, TIMES, UMINUS, LPAREN, RPAREN;
15 | terminal Integer NUMBER; // our scanner provides numbers as integers
16 |
17 | /* Non terminals */
18 | non terminal expr_list;
19 | non terminal Integer expr; // used to store evaluated subexpressions
20 |
21 | /* Precedences */
22 | precedence left PLUS, MINUS;
23 | precedence left TIMES;
24 | precedence left UMINUS;
25 |
26 | /* The grammar rules */
27 | expr_list ::= expr_list expr:e SEMI {: System.out.println(e);:}
28 | | expr:e SEMI {: System.out.println(e);:}
29 | ;
30 | expr ::= expr:e1 PLUS expr:e2 {: RESULT = e1+e2; :}
31 | | expr:e1 MINUS expr:e2 {: RESULT = e1-e2; :}
32 | | expr:e1 TIMES expr:e2 {: RESULT = e1*e2; :}
33 | | MINUS expr:e {: RESULT = -e; :}
34 | %prec UMINUS
35 | | LPAREN expr:e RPAREN {: RESULT = e; :}
36 | | NUMBER:n {: RESULT = n; :}
37 | ;
38 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/.gitignore:
--------------------------------------------------------------------------------
1 | output.html
2 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/Constants.java:
--------------------------------------------------------------------------------
1 | public interface Constants {
2 |
3 | public static final int INTTYPE = 1;
4 | public static final int BOOLTYPE = 2;
5 |
6 | public static final int TRUE = 1;
7 | public static final int FALSE = 0;
8 |
9 | public static final int PLUS = 1;
10 | public static final int MINUS = 2;
11 | public static final int MULT = 3;
12 | public static final int DIV = 4;
13 | public static final int MOD = 5;
14 |
15 | public static final int LEQ = 1;
16 | public static final int LE = 2;
17 | public static final int GT = 3;
18 | public static final int GTQ = 4;
19 | public static final int EQ = 5;
20 | public static final int NEQ = 6;
21 | public static final int AND = 7;
22 | public static final int OR = 8;
23 |
24 |
25 | }
26 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/c/.gitignore:
--------------------------------------------------------------------------------
1 | *.java
2 | *.class
3 | *.xml
4 | output.html
5 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/c/input.c:
--------------------------------------------------------------------------------
1 | int a=0;
2 |
3 | int c;
4 |
5 | void main(int d, int e){
6 | int f = 3;
7 | int h=f, b=0;
8 | h + 1;
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/c/makeTest.sh:
--------------------------------------------------------------------------------
1 | rm *.java
2 | rm *.class
3 | jflex c.jflex
4 | ../../bin/cup.sh -locations -interface -parser Parser -xmlactions c.cup
5 | javac -cp ../../dist/java-cup-11b-runtime.jar:. *.java
6 | java -cp ../../dist/java-cup-11b-runtime.jar:. Parser input.c simple.xml
7 | java -cp ../../dist/java-cup-11b-runtime.jar:. Parser complicated.c complicated.xml
8 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/c/tree-view.css:
--------------------------------------------------------------------------------
1 | body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black }
2 |
3 | .connector { font-family: monospace; }
4 |
5 | .name { color: navy; background-color: white; text-decoration: underline; font-weight: bold;
6 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
7 | .altname { color: navy; text-decoration: underline }
8 | .uri { color: #444; font-style: italic }
9 | .value { color: #040; background-color: #CCC; font-weight: bold }
10 | .escape { color: #620; font-family: monospace }
11 |
12 | .root { color: yellow; background-color: black }
13 | .element { color: yellow; background-color: navy }
14 | .namespace { color: yellow; background-color: #333 }
15 | .attribute { color: yellow; background-color: #040 }
16 | .text { color: yellow; background-color: #400 }
17 | .pi { color: yellow; background-color: #044 }
18 | .comment { color: yellow; background-color: #303 }
19 |
20 | .root,.element,.attribute,.namespace,.text,.comment,.pi
21 | { font-weight: bold;
22 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
23 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/calc/.gitignore:
--------------------------------------------------------------------------------
1 | *.java
2 | *.class
3 | *.xml
4 | output.html
5 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/calc/calc.cup:
--------------------------------------------------------------------------------
1 | /* Simple +/-/* expression language; parser evaluates constant expressions on the fly*/
2 | import java_cup.runtime.*;
3 |
4 | parser code {:
5 | scanner s;
6 | Parser(scanner s){
7 | this.s=s;
8 | }
9 | :}
10 | init with {: s.init(); :};
11 | scan with {: return s.next_token(); :};
12 | /* Terminals (tokens returned by the scanner). */
13 | terminal SEMI, PLUS, MINUS, TIMES, UMINUS, LPAREN, RPAREN;
14 | terminal Integer NUMBER; // our scanner provides numbers as integers
15 |
16 | /* Non terminals */
17 | non terminal expr_list;
18 | non terminal Integer expr; // used to store evaluated subexpressions
19 |
20 | /* Precedences */
21 | precedence left PLUS, MINUS;
22 | precedence left TIMES;
23 | precedence left UMINUS;
24 |
25 | /* The grammar rules */
26 | expr_list ::= expr_list expr:e SEMI {: System.out.println(e);:}
27 | | expr:e SEMI {: System.out.println(e);:}
28 | ;
29 | expr ::= expr:e1 PLUS expr:e2 {: RESULT = e1+e2; :}
30 | | expr:e1 MINUS expr:e2 {: RESULT = e1-e2; :}
31 | | expr:e1 TIMES expr:e2 {: RESULT = e1*e2; :}
32 | | MINUS expr:e {: RESULT = -e; :}
33 | %prec UMINUS
34 | | LPAREN expr:e RPAREN {: RESULT = e; :}
35 | | NUMBER:n {: RESULT = n; :}
36 | ;
37 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/calc/makeCalc.sh:
--------------------------------------------------------------------------------
1 | ../../bin/cup.sh -interface -parser Parser calc.cup
2 | javac -cp ../../dist/java-cup-11b-runtime.jar:. *.java
3 | java -cp ../../dist/java-cup-11b-runtime.jar:. Main
4 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/input.minijava:
--------------------------------------------------------------------------------
1 | int x, y;
2 | y = 10;
3 | x = read();
4 | while (1-y <= -x) {
5 | y = x * (-y + 5);
6 | }
7 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/makeAnnotatedTest.sh:
--------------------------------------------------------------------------------
1 | mkdir -p out
2 | ../bin/cup.sh -destdir out -interface -parser Parser -xmlactions test-correctannotations.cup
3 | javac -cp ../dist/java-cup-11b-runtime.jar:.:out/ -d out *.java out/*.java
4 | java -cp ../dist/java-cup-11b-runtime.jar:.:out/ Parser input.minijava out/test_annotated.xml
5 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/makeNonAnnotatedTest.sh:
--------------------------------------------------------------------------------
1 | mkdir -p out
2 | ../bin/cup.sh -destdir out -interface -parser Parser -xmlactions -genericlabels test-noannotations.cup
3 | javac -cp ../dist/java-cup-11b-runtime.jar:.:out/ -d out *.java out/*.java
4 | java -cp ../dist/java-cup-11b-runtime.jar:.:out/ Parser input.minijava out/test_not_annotated.xml
5 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/makeXMLtest.sh:
--------------------------------------------------------------------------------
1 | mkdir -p out
2 | ../bin/cup.sh -destdir out -interface -parser Parser -xmlactions test2.cup
3 | javac -cp ../dist/java-cup-11b-runtime.jar:.:out/ *.java out/*.java
4 | java -cp ../dist/java-cup-11b-runtime.jar:.:out/ Parser input.minijava out/test_xml.xml
5 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava/TestVisitor.java:
--------------------------------------------------------------------------------
1 | import java_cup.runtime.SyntaxTreeDFS.AbstractVisitor;
2 | import java_cup.runtime.SyntaxTreeDFS;
3 | import java_cup.runtime.XMLElement;
4 | import java.util.List;
5 |
6 | public class TestVisitor extends AbstractVisitor {
7 | public TestVisitor(){
8 | registerPreVisit("stmt",this::preVisitStatement);
9 | }
10 | public void preVisitStatement(XMLElement element, List children){
11 | System.out.println("Found a statement");
12 | SyntaxTreeDFS.dfs(element,new TerminalFilter());
13 | }
14 | public void defaultPre(XMLElement elem, List children) {}
15 | public void defaultPost(XMLElement elem, List children) {}
16 | }
17 |
18 | class TerminalFilter extends AbstractVisitor {
19 | public void defaultPre(XMLElement elem, List children) {
20 | if (elem instanceof XMLElement.Terminal)
21 | System.out.println(""+elem);
22 | }
23 | public void defaultPost(XMLElement elem, List children) {}
24 | }
25 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava/make.sh:
--------------------------------------------------------------------------------
1 | rm Parser.java Lexer.java
2 | rm *.class
3 | jflex minijava.jflex
4 | ../../bin/cup.sh -locations -interface -parser Parser -xmlactions minijava.cup
5 | javac -cp ../../dist/java-cup-11b-runtime.jar:. *.java
6 | java -cp ../../dist/java-cup-11b-runtime.jar:. Parser simple.minijava simple.xml /
7 | basex codegen.sq output.xml > simple.minijvm
8 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava/simple.minijava:
--------------------------------------------------------------------------------
1 | int x, y;
2 | y = 10;
3 | x = read();
4 | write(x);
5 | if (x>=0)
6 | write (y);
7 | else
8 | write (x);
9 | while (1-y <= -x) {
10 | y = x * (-y + 5);
11 | }
12 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava/tree-view.css:
--------------------------------------------------------------------------------
1 | body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black }
2 |
3 | .connector { font-family: monospace; }
4 |
5 | .name { color: navy; background-color: white; text-decoration: underline; font-weight: bold;
6 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
7 | .altname { color: navy; text-decoration: underline }
8 | .uri { color: #444; font-style: italic }
9 | .value { color: #040; background-color: #CCC; font-weight: bold }
10 | .escape { color: #620; font-family: monospace }
11 |
12 | .root { color: yellow; background-color: black }
13 | .element { color: yellow; background-color: navy }
14 | .namespace { color: yellow; background-color: #333 }
15 | .attribute { color: yellow; background-color: #040 }
16 | .text { color: yellow; background-color: #400 }
17 | .pi { color: yellow; background-color: #044 }
18 | .comment { color: yellow; background-color: #303 }
19 |
20 | .root,.element,.attribute,.namespace,.text,.comment,.pi
21 | { font-weight: bold;
22 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
23 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/bin/JFlex.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/examples/cup/testgrammars/minijava2/bin/JFlex.jar
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/expres.mp:
--------------------------------------------------------------------------------
1 | verbatimtex
2 | etex
3 |
4 | input expressg;
5 |
6 | beginfig(1);
7 | z3=(0,0);
8 | drawovalbox(3,40,17)(btex \tt start etex);
9 | z1c=z3c-(0,40);
10 | drawdiamondbox(1,45,25)(btex \tt x > 5 etex);
11 | z2c=z1c-(0,40);
12 | drawLEVENT(2,55,15)(btex \tt x=read(); etex);
13 | z4c=z2c-(0,40);
14 | drawENT(4,40,15)(btex \tt x=5; etex);
15 | z5=z3c-(0,160);
16 | drawovalbox(5,40,17)(btex \tt stop etex);
17 |
18 | drawnormalCA(3bm,1tm);
19 | drawnormalCA(2bm,4tm);
20 | drawnormalCA(4bm,5tm);
21 | endfig;
22 | end;
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/input.minijava:
--------------------------------------------------------------------------------
1 | int x, y;
2 | y = 10;
3 | x = read();
4 | read();
5 | while (1-y <= -x) {
6 | y = x * (-y + 5);
7 | }
8 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/src/minijava/Constants.java:
--------------------------------------------------------------------------------
1 | // Technische Universitaet Muenchen
2 | // Fakultaet fuer Informatik
3 | // Riitta Hoellerer
4 | //
5 | // Praktikum des Uebersetzerbaus
6 | // SS 2001
7 | //
8 | // interface containing constants (for Lexer, IdentificationVisitor and
9 | // EmitCodeVisitor)
10 | //
11 | package minijava;
12 | public interface Constants {
13 |
14 | public static final int INTTYPE = 1;
15 | public static final int BOOLTYPE = 2;
16 |
17 | public static final int TRUE = 1;
18 | public static final int FALSE = 0;
19 |
20 | public static final int PLUS = 1;
21 | public static final int MINUS = 2;
22 | public static final int MULT = 3;
23 | public static final int DIV = 4;
24 | public static final int MOD = 5;
25 |
26 | public static final int LEQ = 1;
27 | public static final int LE = 2;
28 | public static final int GT = 3;
29 | public static final int GTQ = 4;
30 | public static final int EQ = 5;
31 | public static final int NEQ = 6;
32 | public static final int AND = 7;
33 | public static final int OR = 8;
34 |
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/src/minijava/Decl.java:
--------------------------------------------------------------------------------
1 | package minijava;
2 | import java.util.List;
3 | public class Decl {
4 | public List varlist;
5 | public Decl(List l){
6 | varlist = l;
7 | }
8 | public String toString(){
9 | String ret = "int "+varlist.get(0);
10 | for (int i = 1; i < varlist.size(); i++) ret += ","+varlist.get(i);
11 | return ret+";\n";
12 | }
13 | public void accept(MinijavaVisitor v){
14 | v.preVisit(this);
15 | v.postVisit(this);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/src/minijava/InMemoryParser.java:
--------------------------------------------------------------------------------
1 | package minijava;
2 |
3 | import java.io.InputStream;
4 |
5 | import java_cup.runtime.ComplexSymbolFactory;
6 | import minijava.Program;
7 | import miniparser.*;
8 |
9 | public class InMemoryParser {
10 | private InputStream in;
11 | public InMemoryParser(InputStream in) {
12 | this.in=in;
13 | }
14 | public Program parse() throws Exception {
15 | Lexer scanner = null;
16 | ComplexSymbolFactory csf = new ComplexSymbolFactory();
17 | scanner = new Lexer( new java.io.InputStreamReader(in),csf );
18 | Parser p = new Parser(scanner, csf);
19 | return (Program)p.parse().value;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/minijava2/src/minijava/Program.java:
--------------------------------------------------------------------------------
1 | package minijava;
2 | import java.util.List;
3 | public class Program extends Stmt.Compound {
4 | public List ld;
5 | public Program(List ld, List ls){
6 | super(ls);
7 | this.ld = ld;
8 | }
9 | public String toString(){
10 | String ret="" ;
11 | for (Decl d: ld) ret += d;
12 | for (Stmt s: ls) ret += s;
13 | return ret;
14 | }
15 | public void accept(MinijavaVisitor v){
16 | if (!v.preVisit(this)) return;
17 | for (Decl d: ld) d.accept(v);
18 | for (Stmt s: ls) s.accept(v);
19 | v.postVisit(this);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/examples/cup/testgrammars/tree-view.css:
--------------------------------------------------------------------------------
1 | body { font-family: sans-serif; font-size: 80%; background-color: #EAEAD9; color: black }
2 |
3 | .connector { font-family: monospace; }
4 |
5 | .name { color: navy; background-color: white; text-decoration: underline; font-weight: bold;
6 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
7 | .altname { color: navy; text-decoration: underline }
8 | .uri { color: #444; font-style: italic }
9 | .value { color: #040; background-color: #CCC; font-weight: bold }
10 | .escape { color: #620; font-family: monospace }
11 |
12 | .root { color: yellow; background-color: black }
13 | .element { color: yellow; background-color: navy }
14 | .namespace { color: yellow; background-color: #333 }
15 | .attribute { color: yellow; background-color: #040 }
16 | .text { color: yellow; background-color: #400 }
17 | .pi { color: yellow; background-color: #044 }
18 | .comment { color: yellow; background-color: #303 }
19 |
20 | .root,.element,.attribute,.namespace,.text,.comment,.pi
21 | { font-weight: bold;
22 | padding-top: 0px; padding-bottom: 1px; padding-left: 3px; padding-right: 3px }
23 |
--------------------------------------------------------------------------------
/jdk-lite/.gitignore:
--------------------------------------------------------------------------------
1 | out/
2 | /bin/
3 |
--------------------------------------------------------------------------------
/jdk-lite/dump.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/jdk-lite/dump.txt
--------------------------------------------------------------------------------
/jdk-lite/native/java/lang/Class.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern "C" {
5 |
6 | jstring JVM_GetClassName(JNIEnv *env, jclass cls);
7 |
8 | // Need mutable C-strings here, for RegisterNatives to accept them.
9 | char getNameName[] = "getName";
10 | char getNameSig[] = "()Ljava/lang/String;";
11 |
12 | static JNINativeMethod methods[] = {
13 | {getNameName, getNameSig, (void*) &JVM_GetClassName},
14 | };
15 |
16 | void Java_java_lang_Class_registerNatives(JNIEnv *env, jclass clazz) {
17 | env->RegisterNatives(clazz, methods, sizeof(methods)/sizeof(JNINativeMethod));
18 | }
19 |
20 | } // extern "C"
21 |
--------------------------------------------------------------------------------
/jdk-lite/native/java/lang/Object.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 |
4 | extern "C" {
5 |
6 | jint Java_java_lang_Object_hashCode__(JNIEnv* env, jobject o) {
7 | auto addr = reinterpret_cast(o);
8 | return static_cast(addr);
9 | }
10 |
11 | jclass Java_java_lang_Object_getClass__(JNIEnv* env, jobject o) {
12 | return env->GetObjectClass(o);
13 | }
14 |
15 | } // extern "C"
16 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/io/PrintStream.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.io;
4 |
5 | // Hack to easily get console I/O.
6 | public class PrintStream {
7 |
8 | public void print(Object o) {
9 | print(o == null ? "null" : o.toString());
10 | }
11 |
12 | public void println(Object o) {
13 | println(o == null ? "null" : o.toString());
14 | }
15 |
16 | public native void println();
17 |
18 | public native void print(String s);
19 | public native void println(String s);
20 |
21 | public native void print(boolean n);
22 | public native void println(boolean n);
23 |
24 | public native void print(byte n);
25 | public native void println(byte n);
26 |
27 | public native void print(char c);
28 | public native void println(char c);
29 |
30 | public native void print(short n);
31 | public native void println(short n);
32 |
33 | public native void print(int n);
34 | public native void println(int n);
35 |
36 | public native void print(long n);
37 | public native void println(long n);
38 |
39 | public native void print(float n);
40 | public native void println(float n);
41 |
42 | public native void print(double n);
43 | public native void println(double n);
44 |
45 | public native void flush();
46 | }
47 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/io/Serializable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.io;
4 |
5 | public interface Serializable {
6 | }
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/ArrayIndexOutOfBoundsException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class ArrayIndexOutOfBoundsException extends IndexOutOfBoundsException {
7 |
8 | public ArrayIndexOutOfBoundsException() {
9 | super();
10 | }
11 |
12 | public ArrayIndexOutOfBoundsException(int index) {
13 | super("Array index out of range: " );
14 | }
15 |
16 | public ArrayIndexOutOfBoundsException(String s) {
17 | super(s);
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/ArrayStoreException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class ArrayStoreException extends RuntimeException {
7 |
8 | public ArrayStoreException() {
9 | super();
10 | }
11 |
12 | public ArrayStoreException(String s) {
13 | super(s);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/AssertionError.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class AssertionError extends Error {
6 |
7 | public AssertionError() {
8 | }
9 |
10 | private AssertionError(String detailMessage) {
11 | super(detailMessage);
12 | }
13 |
14 | public AssertionError(Object detailMessage) {
15 | this(detailMessage.toString());
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/AutoCloseable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public interface AutoCloseable {
6 | void close() throws Exception;
7 | }
8 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Class.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public final class Class {
6 |
7 | private static native void registerNatives();
8 | static {
9 | registerNatives();
10 | }
11 |
12 | public static Class forName(String name) {
13 | throw new RuntimeException("unimplemented");
14 | }
15 |
16 | public native String getName();
17 |
18 | public String toString() {
19 | String name = getName();
20 | switch (name) {
21 | case "void":
22 | case "boolean":
23 | case "byte":
24 | case "char":
25 | case "short":
26 | case "int":
27 | case "long":
28 | case "float":
29 | case "double":
30 | return name;
31 | default:
32 | return "class " + name;
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/ClassCastException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class ClassCastException extends RuntimeException {
7 |
8 | public ClassCastException() {
9 | super();
10 | }
11 |
12 | public ClassCastException(String s) {
13 | super(s);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/ClassNotFoundException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class ClassNotFoundException extends Exception {
6 |
7 | public ClassNotFoundException() {
8 | super();
9 | }
10 |
11 | public ClassNotFoundException(String s) {
12 | super(s);
13 | }
14 |
15 | public ClassNotFoundException(String s, Throwable t) {
16 | super(s, t);
17 | }
18 | }
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/CloneNotSupportedException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class CloneNotSupportedException extends Exception {
7 |
8 | public CloneNotSupportedException() {
9 | super();
10 | }
11 |
12 | public CloneNotSupportedException(String s) {
13 | super(s);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Cloneable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public interface Cloneable {
6 | }
7 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Comparable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public interface Comparable {
6 | public int compareTo(T o);
7 | }
8 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Enum.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | import java.io.Serializable;
6 | import java.io.ObjectInputStream;
7 |
8 | public abstract class Enum> implements Serializable {
9 | private final String name;
10 |
11 | public final String name() {
12 | return name;
13 | }
14 |
15 | private final int ordinal;
16 |
17 | public final int ordinal() {
18 | return ordinal;
19 | }
20 |
21 | protected Enum(String name, int ordinal) {
22 | this.name = name;
23 | this.ordinal = ordinal;
24 | }
25 |
26 | public String toString() {
27 | return name;
28 | }
29 |
30 | public final boolean equals(Object other) {
31 | return this == other;
32 | }
33 |
34 | public final int hashCode() {
35 | return super.hashCode();
36 | }
37 |
38 | protected final Object clone() {
39 | return this;
40 | }
41 |
42 | public final int compareTo(E o) {
43 | return 0;
44 | }
45 |
46 | public final Class getDeclaringClass() {
47 | return null;
48 | }
49 |
50 | public static > T valueOf(Class enumType,
51 | String name) {
52 | throw new RuntimeException("java.lang.Enum#valueOf unimplemented");
53 | }
54 |
55 | private void readObject(ObjectInputStream in) {}
56 |
57 | private void readObjectNoData() {}
58 | }
59 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Error.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class Error extends Throwable {
6 |
7 | public Error() {
8 | super();
9 | }
10 |
11 | public Error(String message) {
12 | super(message);
13 | }
14 |
15 | public Error(String message, Throwable cause) {
16 | super(message, cause);
17 | }
18 |
19 | public Error(Throwable cause) {
20 | super(cause);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Exception.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class Exception extends Throwable {
6 |
7 | public Exception() {
8 | super();
9 | }
10 |
11 | public Exception(String message) {
12 | super(message);
13 | }
14 |
15 | public Exception(String message, Throwable cause) {
16 | super(message, cause);
17 | }
18 |
19 | public Exception(Throwable cause) {
20 | super(cause);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Float.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public final class Float extends Number {
6 | private final float value;
7 |
8 | public static String toString(float f) {
9 | return String.valueOf(f);
10 | }
11 |
12 | public Float(float value) {
13 | this.value = value;
14 | }
15 |
16 | public String toString() {
17 | return Float.toString(value);
18 | }
19 |
20 | public float floatValue() {
21 | return value;
22 | }
23 |
24 | public static boolean isNaN(float f) {
25 | return f != f;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/IllegalArgumentException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class IllegalArgumentException extends RuntimeException {
7 |
8 | public IllegalArgumentException() {
9 | super();
10 | }
11 |
12 | public IllegalArgumentException(String s) {
13 | super(s);
14 | }
15 |
16 | public IllegalArgumentException(String message, Throwable cause) {
17 | super(message, cause);
18 | }
19 |
20 | public IllegalArgumentException(Throwable cause) {
21 | super(cause);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/IllegalStateException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class IllegalStateException extends RuntimeException {
7 |
8 | public IllegalStateException() {
9 | super();
10 | }
11 |
12 | public IllegalStateException(String s) {
13 | super(s);
14 | }
15 |
16 | public IllegalStateException(String message, Throwable cause) {
17 | super(message, cause);
18 | }
19 |
20 | public IllegalStateException(Throwable cause) {
21 | super(cause);
22 | }
23 |
24 | }
25 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/IndexOutOfBoundsException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public
6 | class IndexOutOfBoundsException extends RuntimeException {
7 |
8 | public IndexOutOfBoundsException() {
9 | super();
10 | }
11 |
12 | public IndexOutOfBoundsException(String s) {
13 | super(s);
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Integer.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public final class Integer extends Number {
6 |
7 | public static final int MAX_VALUE = 214748364;
8 |
9 | public static String toString(int i) {
10 | return String.valueOf(i);
11 | }
12 |
13 | public static Integer valueOf(int i) {
14 | return new Integer(i);
15 | }
16 |
17 | private final int value;
18 |
19 | public Integer(int value) {
20 | this.value = value;
21 | }
22 |
23 | public int intValue() {
24 | return value;
25 | }
26 |
27 | public float floatValue() {
28 | return (float) value;
29 | }
30 |
31 | public String toString() {
32 | return toString(value);
33 | }
34 |
35 | public int hashCode() {
36 | return value;
37 | }
38 |
39 | public boolean equals(Object obj) {
40 | if (obj instanceof Integer) {
41 | return value == ((Integer) obj).intValue();
42 | }
43 | return false;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Iterable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | import java.util.Iterator;
6 |
7 | public interface Iterable {
8 |
9 | Iterator iterator();
10 | }
11 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/JLangNotImplementedError.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class JLangNotImplementedError extends RuntimeException {
6 |
7 | public JLangNotImplementedError() {
8 | super();
9 | }
10 |
11 | public JLangNotImplementedError(String s) {
12 | super(s);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/NullPointerException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class NullPointerException extends RuntimeException {
6 |
7 | public NullPointerException() { super(); }
8 |
9 | public NullPointerException(String s) { super(s); }
10 | }
11 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Number.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class Number {}
6 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Object.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class Object {
6 |
7 | protected Object clone() throws CloneNotSupportedException {
8 | return this;
9 | }
10 |
11 | public boolean equals(Object other) {
12 | return this == other;
13 | }
14 |
15 | protected final void finalize() throws Throwable {
16 | throw new RuntimeException("Object#finalize() not implemented");
17 | }
18 |
19 | public final native Class> getClass();
20 |
21 | public native int hashCode();
22 |
23 | public final void notify() {
24 | throw new RuntimeException("Object#notify() not implemented");
25 | }
26 |
27 | public final void notifyAll() {
28 | throw new RuntimeException("Object#notifyAll() not implemented");
29 | }
30 |
31 | public String toString() {
32 | throw new RuntimeException("Object#toString() not implemented");
33 | }
34 |
35 | public final void wait(long timeout) {
36 | throw new RuntimeException("Object#wait(long) not implemented");
37 | }
38 |
39 | public final void wait(long timeout, int nanos) {
40 | throw new RuntimeException("Object#wait(long,int) not implemented");
41 | }
42 |
43 | public final void wait() {
44 | throw new RuntimeException("Object#wait() not implemented");
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Runnable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public interface Runnable {
6 |
7 | void run();
8 | }
9 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/RuntimeException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class RuntimeException extends Exception {
6 |
7 | public RuntimeException() {
8 | super();
9 | }
10 |
11 | public RuntimeException(String message) {
12 | super(message);
13 | }
14 |
15 | public RuntimeException(String message, Throwable cause) {
16 | super(message, cause);
17 | }
18 |
19 | public RuntimeException(Throwable cause) {
20 | super(cause);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/System.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | import java.io.PrintStream;
6 |
7 | public class System {
8 | public static PrintStream out = new PrintStream();
9 |
10 | public static void initializeSystemClass() {
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/Throwable.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class Throwable {
6 | private String detailMessage;
7 | private Throwable cause;
8 | private Throwable suppressed;
9 |
10 | public Throwable() {}
11 |
12 | public Throwable(String s) { this(s, null); }
13 |
14 | public Throwable(String s, Throwable t) {
15 | this.detailMessage = s;
16 | }
17 |
18 | public Throwable(Throwable t) {
19 | this.detailMessage = t.detailMessage;
20 | this.cause = t;
21 | }
22 |
23 | void addSuppressed(Throwable t) {
24 | this.suppressed = t;
25 | }
26 |
27 | public String getMessage() { return detailMessage; }
28 | public String getLocalizedMessage() {return detailMessage;}
29 | public String toString() { return detailMessage; }
30 | }
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/UnsupportedOperationException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang;
4 |
5 | public class UnsupportedOperationException extends RuntimeException {
6 |
7 | public UnsupportedOperationException() {
8 | }
9 |
10 | public UnsupportedOperationException(String message) {
11 | super(message);
12 | }
13 |
14 | public UnsupportedOperationException(String message, Throwable cause) {
15 | super(message, cause);
16 | }
17 |
18 | public UnsupportedOperationException(Throwable cause) {
19 | super(cause);
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/lang/annotation/Annotation.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.lang.annotation;
4 |
5 | public interface Annotation {
6 |
7 | boolean equals(Object obj);
8 |
9 | int hashCode();
10 |
11 | String toString();
12 |
13 | Class extends Annotation> annotationType();
14 | }
15 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/test/AbstractTest.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.test;
4 |
5 | public abstract class AbstractTest {
6 |
7 | public abstract String message();
8 |
9 | public void printMessage() {
10 | System.out.println("My message is: " + message());
11 | }
12 |
13 | }
14 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/test/SubTest.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.test;
4 |
5 | public class SubTest extends Test {
6 |
7 | public void init() {
8 | this.setMessage("Sub Message");
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/test/Test.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.test;
4 |
5 | public class Test extends AbstractTest {
6 |
7 | private String message;
8 |
9 | public Test() {
10 | init();
11 | }
12 |
13 | public void init() {
14 | this.message = "Base Message";
15 | }
16 |
17 | public void setMessage(String msg) {
18 | this.message = msg;
19 | }
20 |
21 | public String message() {
22 | return this.message;
23 | }
24 |
25 |
26 | }
27 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/Collection.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public interface Collection extends Iterable {
6 |
7 | int size();
8 |
9 | boolean isEmpty();
10 |
11 | boolean contains(Object o);
12 |
13 | Iterator iterator();
14 |
15 | Object[] toArray();
16 |
17 | T[] toArray(T[] a);
18 |
19 | boolean add(E e);
20 |
21 | boolean remove(Object o);
22 |
23 | boolean containsAll(Collection> c);
24 |
25 | boolean addAll(Collection extends E> c);
26 |
27 | boolean removeAll(Collection> c);
28 |
29 | boolean retainAll(Collection> c);
30 |
31 | void clear();
32 |
33 | boolean equals(Object o);
34 |
35 | int hashCode();
36 | }
37 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/ConcurrentModificationException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public class ConcurrentModificationException extends RuntimeException {
6 |
7 | public ConcurrentModificationException() {
8 | }
9 |
10 | public ConcurrentModificationException(String message) {
11 | super(message);
12 | }
13 |
14 | public ConcurrentModificationException(Throwable cause) {
15 | super(cause);
16 | }
17 |
18 | public ConcurrentModificationException(String message, Throwable cause) {
19 | super(message, cause);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/Iterator.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public interface Iterator {
6 |
7 | boolean hasNext();
8 |
9 | E next();
10 |
11 | void remove();
12 | }
13 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/List.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public interface List extends Collection {
6 |
7 | int size();
8 |
9 | boolean isEmpty();
10 |
11 | boolean contains(Object o);
12 |
13 | Iterator iterator();
14 |
15 | Object[] toArray();
16 |
17 | T[] toArray(T[] a);
18 |
19 | boolean add(E e);
20 |
21 | boolean remove(Object o);
22 |
23 | boolean containsAll(Collection> c);
24 |
25 | boolean addAll(Collection extends E> c);
26 |
27 | boolean addAll(int index, Collection extends E> c);
28 |
29 | boolean removeAll(Collection> c);
30 |
31 | boolean retainAll(Collection> c);
32 |
33 | void clear();
34 |
35 | boolean equals(Object o);
36 |
37 | int hashCode();
38 |
39 | E get(int index);
40 |
41 | E set(int index, E element);
42 |
43 | void add(int index, E element);
44 |
45 | E remove(int index);
46 |
47 | int indexOf(Object o);
48 |
49 | int lastIndexOf(Object o);
50 |
51 | ListIterator listIterator();
52 |
53 | ListIterator listIterator(int index);
54 |
55 | List subList(int fromIndex, int toIndex);
56 | }
57 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/ListIterator.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public interface ListIterator extends Iterator {
6 |
7 | boolean hasNext();
8 |
9 | E next();
10 |
11 | boolean hasPrevious();
12 |
13 | E previous();
14 |
15 | int nextIndex();
16 |
17 | int previousIndex();
18 |
19 | void remove();
20 |
21 | void set(E e);
22 |
23 | void add(E e);
24 | }
25 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/NoSuchElementException.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public class NoSuchElementException extends RuntimeException {
6 |
7 | public NoSuchElementException() {
8 | super();
9 | }
10 |
11 | public NoSuchElementException(String s) {
12 | super(s);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/jdk-lite/src/java/util/RandomAccess.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package java.util;
4 |
5 | public interface RandomAccess {
6 | }
7 |
--------------------------------------------------------------------------------
/jdk/.gitignore:
--------------------------------------------------------------------------------
1 | src/
2 | src.orig/
3 | out/
4 |
--------------------------------------------------------------------------------
/jdk/Main.java:
--------------------------------------------------------------------------------
1 | class Main {
2 | public static void main(String[] args) {
3 | System.out.println("begin");
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/jdk/Makefile.obj:
--------------------------------------------------------------------------------
1 | OUT := out
2 | LL := $(shell find $(OUT) -name "*.ll")
3 | OBJ := $(LL:%.ll=%.o)
4 |
5 | all: $(OBJ)
6 | .PHONY: all
7 |
8 | $(OBJ): %.o: %.ll $(OUT)/llstamp
9 | @echo "Compiling $<"
10 | @$(CLANG) -Wno-override-module -fPIC -c -o $@ $<
11 |
--------------------------------------------------------------------------------
/jdk/make-patch.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | if [ $# -eq 0 ]; then
3 | echo "Example usage: $0 java/lang/Object.java"
4 | exit 1
5 | fi
6 |
7 | SRC=src
8 |
9 | set -e
10 | mkdir -p `dirname patches/"$1"`
11 | if [ ! -f "${SRC}.orig/$1" ]; then
12 | touch "${SRC}.orig/$1"
13 | fi
14 | diff -u "${SRC}.orig/$1" "$SRC/$1" > "patches/${1%.java}.patch"
15 |
--------------------------------------------------------------------------------
/jdk/modification_notice.txt:
--------------------------------------------------------------------------------
1 | // This file's original contents have been modified
2 | // by a JLang patch on XXDATEXX (the date this source code was compiled)
3 |
--------------------------------------------------------------------------------
/jdk/patches/java/io/FileDescriptor.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/io/FileDescriptor.java 2018-08-02 12:23:56.000000000 -0400
2 | +++ src/java/io/FileDescriptor.java 2018-08-02 13:32:41.000000000 -0400
3 | @@ -165,6 +165,7 @@
4 | private static FileDescriptor standardStream(int fd) {
5 | FileDescriptor desc = new FileDescriptor();
6 | desc.handle = set(fd);
7 | + desc.fd = fd;
8 | return desc;
9 | }
10 |
11 |
--------------------------------------------------------------------------------
/jdk/patches/java/io/FileInputStream.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/io/FileInputStream.java 2013-01-04 14:04:02.000000000 -0500
2 | +++ src/java/io/FileInputStream.java 2018-05-13 17:45:35.000000000 -0400
3 | @@ -56,13 +56,8 @@
4 | private final Object closeLock = new Object();
5 | private volatile boolean closed = false;
6 |
7 | - private static final ThreadLocal runningFinalize =
8 | - new ThreadLocal<>();
9 | -
10 | + // Modified for JLang.
11 | private static boolean isRunningFinalize() {
12 | - Boolean val;
13 | - if ((val = runningFinalize.get()) != null)
14 | - return val.booleanValue();
15 | return false;
16 | }
17 |
18 | @@ -397,12 +392,8 @@
19 | * stream is still using it. If the user directly invokes
20 | * close() then the FileDescriptor is also released.
21 | */
22 | - runningFinalize.set(Boolean.TRUE);
23 | - try {
24 | - close();
25 | - } finally {
26 | - runningFinalize.set(Boolean.FALSE);
27 | - }
28 | + // Modified for JLang.
29 | + close();
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/jdk/patches/java/nio/charset/ArrayDecoder.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/nio/charset/ArrayDecoder.java 2018-07-23 13:58:08.000000000 -0400
2 | +++ src/java/nio/charset/ArrayDecoder.java 2018-07-23 13:52:29.000000000 -0400
3 | @@ -0,0 +1,35 @@
4 | +/*
5 | + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
6 | + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
7 | + *
8 | + *
9 | + *
10 | + *
11 | + *
12 | + *
13 | + *
14 | + *
15 | + *
16 | + *
17 | + *
18 | + *
19 | + *
20 | + *
21 | + *
22 | + *
23 | + *
24 | + *
25 | + *
26 | + *
27 | + */
28 | +
29 | +package java.nio.charset;
30 | +
31 | +/*
32 | + * FastPath byte[]->char[] decoder, REPLACE on malformed or
33 | + * unmappable input.
34 | + */
35 | +
36 | +public interface ArrayDecoder {
37 | + int decode(byte[] src, int off, int len, char[] dst);
38 | +}
39 |
--------------------------------------------------------------------------------
/jdk/patches/java/nio/charset/ArrayEncoder.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/nio/charset/ArrayEncoder.java 2018-07-23 13:58:13.000000000 -0400
2 | +++ src/java/nio/charset/ArrayEncoder.java 2018-07-23 13:52:29.000000000 -0400
3 | @@ -0,0 +1,35 @@
4 | +/*
5 | + * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
6 | + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
7 | + *
8 | + *
9 | + *
10 | + *
11 | + *
12 | + *
13 | + *
14 | + *
15 | + *
16 | + *
17 | + *
18 | + *
19 | + *
20 | + *
21 | + *
22 | + *
23 | + *
24 | + *
25 | + *
26 | + *
27 | + */
28 | +
29 | +package java.nio.charset;
30 | +
31 | +/*
32 | + * FastPath char[]->byte[] encoder, REPLACE on malformed input or
33 | + * unmappable input.
34 | + */
35 | +
36 | +public interface ArrayEncoder {
37 | + int encode(char[] src, int off, int len, byte[] dst);
38 | +}
39 |
--------------------------------------------------------------------------------
/jdk/patches/java/nio/charset/HistoricallyNamedCharset.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/nio/charset/HistoricallyNamedCharset.java 2018-07-23 14:07:26.000000000 -0400
2 | +++ src/java/nio/charset/HistoricallyNamedCharset.java 2018-07-23 14:07:09.000000000 -0400
3 | @@ -0,0 +1,33 @@
4 | +/*
5 | + * Copyright (c) 2000, Oracle and/or its affiliates. All rights reserved.
6 | + * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
7 | + *
8 | + *
9 | + *
10 | + *
11 | + *
12 | + *
13 | + *
14 | + *
15 | + *
16 | + *
17 | + *
18 | + *
19 | + *
20 | + *
21 | + *
22 | + *
23 | + *
24 | + *
25 | + *
26 | + *
27 | + */
28 | +
29 | +package java.nio.charset;
30 | +
31 | +
32 | +public interface HistoricallyNamedCharset {
33 | +
34 | + public String historicalName();
35 | +
36 | +}
37 |
--------------------------------------------------------------------------------
/jdk/patches/java/nio/charset/StandardCharset.patch:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/jdk/patches/java/nio/charset/StandardCharset.patch
--------------------------------------------------------------------------------
/jdk/patches/java/util/HashMap.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/util/HashMap.java 2018-07-30 17:10:30.000000000 -0400
2 | +++ src/java/util/HashMap.java 2018-07-30 17:29:24.000000000 -0400
3 | @@ -322,6 +322,7 @@
4 |
5 | // internal utilities
6 |
7 | + void alphaMethod() { };
8 | /**
9 | * Initialization hook for subclasses. This method is called
10 | * in all constructors and pseudo-constructors (clone, readObject)
11 |
--------------------------------------------------------------------------------
/jdk/patches/java/util/concurrent/atomic/AtomicInteger.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/java/util/concurrent/atomic/AtomicInteger.java 2013-01-04 14:04:10.000000000 -0500
2 | +++ src/java/util/concurrent/atomic/AtomicInteger.java 2018-05-16 12:29:53.000000000 -0400
3 | @@ -57,10 +57,8 @@
4 | private static final long valueOffset;
5 |
6 | static {
7 | - try {
8 | - valueOffset = unsafe.objectFieldOffset
9 | - (AtomicInteger.class.getDeclaredField("value"));
10 | - } catch (Exception ex) { throw new Error(ex); }
11 | + // Modified for JLang until we have reflection.
12 | + valueOffset = 16;
13 | }
14 |
15 | private volatile int value;
16 |
--------------------------------------------------------------------------------
/jdk/patches/sun/misc/Hashing.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/sun/misc/Hashing.java 2013-01-04 14:04:42.000000000 -0500
2 | +++ src/sun/misc/Hashing.java 2018-05-12 21:02:09.000000000 -0400
3 | @@ -257,12 +257,13 @@
4 | // not practically reversible.
5 | int hashing_seed[] = {
6 | System.identityHashCode(Hashing.class),
7 | - System.identityHashCode(instance),
8 | - System.identityHashCode(Thread.currentThread()),
9 | - (int) Thread.currentThread().getId(),
10 | - (int) (System.currentTimeMillis() >>> 2), // resolution is poor
11 | - (int) (System.nanoTime() >>> 5), // resolution is poor
12 | - (int) (Runtime.getRuntime().freeMemory() >>> 4) // alloc min
13 | + System.identityHashCode(instance)
14 | + // Modified for JLang.
15 | + // System.identityHashCode(Thread.currentThread()),
16 | + // (int) Thread.currentThread().getId(),
17 | + // (int) (System.currentTimeMillis() >>> 2), // resolution is poor
18 | + // (int) (System.nanoTime() >>> 5), // resolution is poor
19 | + // (int) (Runtime.getRuntime().freeMemory() >>> 4) // alloc min
20 | };
21 |
22 | seed = murmur3_32(hashing_seed);
23 |
--------------------------------------------------------------------------------
/jdk/patches/sun/misc/OSEnvironment.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/sun/misc/OSEnvironment.java 2018-08-11 16:32:44.000000000 +0200
2 | +++ src/sun/misc/OSEnvironment.java 2018-08-11 18:13:56.000000000 +0200
3 | @@ -36,7 +36,7 @@
4 | * At this time only the process-wide error mode needs to be set.
5 | */
6 | public static void initialize() {
7 | - Win32ErrorMode.initialize();
8 | + //no-op on Linux + Solaris
9 | }
10 |
11 | }
12 |
--------------------------------------------------------------------------------
/jdk/patches/sun/nio/cs/FastCharsetProvider.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/sun/nio/cs/FastCharsetProvider.java 2018-07-23 14:50:58.000000000 -0400
2 | +++ src/sun/nio/cs/FastCharsetProvider.java 2018-07-23 15:03:04.000000000 -0400
3 | @@ -112,6 +112,14 @@
4 | cs = new US_ASCII();
5 | cache.put(csn, cs);
6 | return cs;
7 | + } else if (cln.equals("UTF_8")) {
8 | + cs = new UTF_8();
9 | + cache.put(csn, cs);
10 | + return cs;
11 | + } else if (cln.equals("ISO_8859_1")) {
12 | + cs = new ISO_8859_1();
13 | + cache.put(csn, cs);
14 | + return cs;
15 | }
16 |
17 | // Instantiate the charset and cache it
18 |
--------------------------------------------------------------------------------
/jdk/patches/sun/reflect/UnsafeFieldAccessorImpl.patch:
--------------------------------------------------------------------------------
1 | --- src.orig/sun/reflect/UnsafeFieldAccessorImpl.java 2019-05-18 20:59:00.000000000 +0800
2 | +++ src/sun/reflect/UnsafeFieldAccessorImpl.java 2019-05-18 21:02:07.000000000 +0800
3 | @@ -40,12 +40,17 @@
4 | static final Unsafe unsafe = Unsafe.getUnsafe();
5 |
6 | protected final Field field;
7 | - protected final int fieldOffset;
8 | + protected final long fieldOffset;
9 | protected final boolean isFinal;
10 |
11 | UnsafeFieldAccessorImpl(Field field) {
12 | this.field = field;
13 | - fieldOffset = unsafe.fieldOffset(field);
14 | + if (Modifier.isStatic(field.getModifiers())) {
15 | + this.fieldOffset = unsafe.staticFieldOffset(field);
16 | + } else {
17 | + this.fieldOffset = unsafe.objectFieldOffset(field);
18 | + }
19 | +
20 | isFinal = Modifier.isFinal(field.getModifiers());
21 | }
22 |
23 |
--------------------------------------------------------------------------------
/jdk/src.zip:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:2df53789a094eeab37e5c85a64a2fba372418e4206297f795fd852ed68762d8f
3 | size 36689314
4 |
--------------------------------------------------------------------------------
/jdk/stubs.cpp:
--------------------------------------------------------------------------------
1 | // This file defines symbols that are otherwise
2 | // missing for various (usually unknown) reasons.
3 | #include
4 | #include
5 | #include "jni.h"
6 |
7 | extern "C" {
8 |
9 | // We always return null, representing the boot class loader.
10 | jobject
11 | Java_java_lang_Class_getClassLoader0(JNIEnv*, jobject) {
12 | return nullptr;
13 | }
14 |
15 | // Pretty sure this only matters on Windows.
16 | jlong
17 | Java_java_io_FileDescriptor_set(JNIEnv *env, jclass fdClass, jint fd) {
18 | return -1;
19 | }
20 |
21 | void Polyglot_java_lang_Enum_compareTo__Ljava_lang_Object_2() {
22 | // For some reason Polyglot adds this method to java.lang.Enum with
23 | // the wrong argument type, in addition to the correct version.
24 | // This should be fixed, because this likely breaks
25 | // method dispatch for enums. For now we abort if called.
26 | fprintf(stderr, "This method should not be called\n");
27 | abort();
28 | }
29 |
30 | } // extern "C"
31 |
--------------------------------------------------------------------------------
/lib/hamcrest-core-1.3.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/hamcrest-core-1.3.jar
--------------------------------------------------------------------------------
/lib/javacpp.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/javacpp.jar
--------------------------------------------------------------------------------
/lib/junit-4.12.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/junit-4.12.jar
--------------------------------------------------------------------------------
/lib/llvm-javadoc.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-javadoc.jar
--------------------------------------------------------------------------------
/lib/llvm-linux-x86_64.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-linux-x86_64.jar
--------------------------------------------------------------------------------
/lib/llvm-macosx-x86_64.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-macosx-x86_64.jar
--------------------------------------------------------------------------------
/lib/llvm-sources.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm-sources.jar
--------------------------------------------------------------------------------
/lib/llvm.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/llvm.jar
--------------------------------------------------------------------------------
/lib/ppg.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/polyglot-compiler/JLang/4cc09d966e2bdae814f21792811c34af589c8f77/lib/ppg.jar
--------------------------------------------------------------------------------
/runtime/.clang-format:
--------------------------------------------------------------------------------
1 | ---
2 | # We'll use defaults from the LLVM style, but with 4 columns indentation.
3 | BasedOnStyle: LLVM
4 | IndentWidth: 4
5 | ---
6 |
--------------------------------------------------------------------------------
/runtime/.gitignore:
--------------------------------------------------------------------------------
1 | out/
2 | runtime.ll
3 | runtime.o
4 |
--------------------------------------------------------------------------------
/runtime/linux_version.map:
--------------------------------------------------------------------------------
1 | SUNWprivate_1.1 {
2 | global:
3 | main;
4 | jni*;
5 | JVM*;
6 | Polyglot*;
7 | jio*;
8 | Java_sun_misc_Unsafe*;
9 | RegisterJavaClass; #TODO rename all of the functions called from JLang-compiled code to have same prefix
10 | createArray;
11 | create1DArray;
12 | InternStringLit;
13 | GetJavaNativeFunc; #Then we can just export PREFIX*
14 | createUnwindException;
15 | extractJavaExceptionObject;
16 | InstanceOf;
17 | throwUnwindException;
18 | __getInterfaceMethod;
19 | __createInterfaceTables;
20 | __java_personality_v0;
21 | __GC_malloc;
22 | getGlobalMutexObject;
23 | local:
24 | *;
25 | };
26 |
27 |
--------------------------------------------------------------------------------
/runtime/native/array.cpp:
--------------------------------------------------------------------------------
1 | #include "array.h"
2 |
3 | extern "C" {
4 | extern void Polyglot_jlang_runtime_Array_load_class();
5 | extern DispatchVector Polyglot_jlang_runtime_Array_cdv;
6 | extern jclass Polyglot_jlang_runtime_Array_class;
7 | }
8 |
9 | static jclass __runtimeArrayClass = nullptr;
10 | static DispatchVector *__runtimeArrayCdv = nullptr;
11 |
12 | static void initRuntimeArray() {
13 | if (__runtimeArrayClass == nullptr && __runtimeArrayCdv == nullptr) {
14 | Polyglot_jlang_runtime_Array_load_class();
15 | __runtimeArrayClass = Polyglot_jlang_runtime_Array_class;
16 | __runtimeArrayCdv = &Polyglot_jlang_runtime_Array_cdv;
17 | }
18 | }
19 |
20 | jclass getRuntimeArrayClass() {
21 | initRuntimeArray();
22 | return __runtimeArrayClass;
23 | }
24 |
25 | DispatchVector *getRuntimeArrayCdv() {
26 | initRuntimeArray();
27 | return __runtimeArrayCdv;
28 | }
--------------------------------------------------------------------------------
/runtime/native/array.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "rep.h"
4 |
5 | jclass getRuntimeArrayClass();
6 | DispatchVector *getRuntimeArrayCdv();
--------------------------------------------------------------------------------
/runtime/native/base_class.cpp:
--------------------------------------------------------------------------------
1 | #include "base_class.h"
2 |
3 | extern "C" {
4 | extern void Polyglot_jlang_runtime_BaseClass_load_class();
5 | extern jclass Polyglot_jlang_runtime_BaseClass_class;
6 | }
7 |
8 | jclass __baseClass = nullptr;
9 |
10 | jclass getBaseClass() {
11 | if (__baseClass == NULL) {
12 | // Force this class load function to be called at initialization
13 | Polyglot_jlang_runtime_BaseClass_load_class();
14 | __baseClass = Polyglot_jlang_runtime_BaseClass_class;
15 | }
16 | return __baseClass;
17 | }
--------------------------------------------------------------------------------
/runtime/native/base_class.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "jni.h"
4 |
5 | /**
6 | * Returns the global base class for primitive types
7 | */
8 | jclass getBaseClass();
--------------------------------------------------------------------------------
/runtime/native/constants.cpp:
--------------------------------------------------------------------------------
1 | #include "constants.h"
2 |
3 | extern "C" {
4 | extern void Polyglot_jlang_runtime_Constants_load_class();
5 | extern int Polyglot_jlang_runtime_Constants_classSize;
6 | extern int Polyglot_jlang_runtime_Constants_numOfRuntimeCdvArrayMethods;
7 | }
8 |
9 | static int __classSize = 0;
10 | static int __numOfRuntimeCdvArrayMethods = 0;
11 |
12 | static void initConstants() {
13 | if (__classSize == 0 && __numOfRuntimeCdvArrayMethods == 0) {
14 | Polyglot_jlang_runtime_Constants_load_class();
15 | __classSize = Polyglot_jlang_runtime_Constants_classSize;
16 | __numOfRuntimeCdvArrayMethods =
17 | Polyglot_jlang_runtime_Constants_numOfRuntimeCdvArrayMethods;
18 | }
19 | }
20 |
21 | int getClassSize() {
22 | initConstants();
23 | return __classSize;
24 | }
25 |
26 | int getNumOfRuntimeArrayCdvMethods() {
27 | initConstants();
28 | return __numOfRuntimeCdvArrayMethods;
29 | }
--------------------------------------------------------------------------------
/runtime/native/constants.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | int getClassSize();
4 |
5 | int getNumOfRuntimeArrayCdvMethods();
--------------------------------------------------------------------------------
/runtime/native/debug.cpp:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | // Helper functions to be used in gdb/lldb.
4 |
5 | std::string make_string(const char *x) { return x; }
--------------------------------------------------------------------------------
/runtime/native/exception.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #pragma once
4 |
5 | #include "jni.h"
6 | #include "rep.h"
7 | #include
8 |
9 | void throwClassNotFoundException(JNIEnv *env, const char *name);
10 | void throwNewThrowable(JNIEnv *env, jclass clazz, const char *msg);
11 | void throwThrowable(JNIEnv *env, jthrowable obj);
12 | void throwInterruptedException(JNIEnv *env);
13 |
14 | extern "C" {
15 |
16 | _Unwind_Exception *createUnwindException(jobject jexception);
17 | void throwUnwindException(_Unwind_Exception *exception);
18 |
19 | } // extern "C"
20 |
--------------------------------------------------------------------------------
/runtime/native/factory.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | // Provides methods to construct common Java objects
4 | // needed by native code. These factory methods directly
5 | // dispatch to symbols compiled from Java code in
6 | // jlang.runtime.Factory.
7 | #pragma once
8 |
9 | #include "jni.h"
10 |
11 | // Arrays.
12 | jbooleanArray CreateJavaBooleanArray(jint len);
13 | jbyteArray CreateJavaByteArray(jint len);
14 | jcharArray CreateJavaCharArray(jint len);
15 | jshortArray CreateJavaShortArray(jint len);
16 | jintArray CreateJavaIntArray(jint len);
17 | jlongArray CreateJavaLongArray(jint len);
18 | jfloatArray CreateJavaFloatArray(jint len);
19 | jdoubleArray CreateJavaDoubleArray(jint len);
20 | jobjectArray CreateJavaObjectArray(jint len);
21 |
22 | // Strings.
23 | jstring CreateJavaString(jcharArray chars);
24 | // Objects.
25 | jobject CreateJavaObject(jclass clazz);
26 | jobject CloneJavaObject(jobject obj);
27 |
--------------------------------------------------------------------------------
/runtime/native/helper.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | // Provides definitions to java runtime functions compiled by JLang
4 |
5 | #pragma once
6 |
7 | #include "jni.h"
8 |
9 | #define POLYGLOT_ARRAY_STORE \
10 | Polyglot_jlang_runtime_Helper_arrayStore___3Ljava_lang_Object_2ILjava_lang_Object_2
11 |
12 | extern "C" {
13 | extern jstring
14 | Polyglot_jlang_runtime_Helper_toString__Ljava_lang_Object_2(jobject);
15 | void POLYGLOT_ARRAY_STORE(jobjectArray, jint, jobject);
16 | extern jobject
17 | Polyglot_jlang_runtime_Helper_arrayLoad___3Ljava_lang_Object_2I(jobject,
18 | jint);
19 | extern void
20 | Polyglot_jlang_runtime_Helper_printString__Ljava_lang_String_2(jstring);
21 | }
--------------------------------------------------------------------------------
/runtime/native/init.cpp:
--------------------------------------------------------------------------------
1 | #include "init.h"
2 |
3 | #include "class.h"
4 | #include "jvm.h"
5 | #include "factory.h"
6 | #include "threads.h"
7 |
8 | extern "C" {
9 | void Polyglot_java_lang_System_initializeSystemClass__();
10 | } // extern "C"
11 |
12 | void InitializeMainThread() {
13 | // initialize classes
14 | FindClass("java.lang.String");
15 | FindClass("java.lang.System");
16 | FindClass("java.lang.Thread");
17 | FindClass("java.lang.ThreadGroup");
18 | FindClass("java.lang.reflect.Method");
19 | FindClass("java.lang.ref.Finalizer");
20 | FindClass("java.lang.Class");
21 |
22 | // setup currentThread for main thread
23 | currentThread = GetMainThread();
24 | Threads::Instance().threads[currentThread].threadStatus = true;
25 |
26 | // initialize the system class
27 | Polyglot_java_lang_System_initializeSystemClass__();
28 | }
--------------------------------------------------------------------------------
/runtime/native/init.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #pragma once
4 |
5 | #include
6 |
7 | void InitializeMainThread();
--------------------------------------------------------------------------------
/runtime/native/interface.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #pragma once
4 |
5 | #include
6 |
7 | extern "C" {
8 |
9 | void *__getInterfaceMethod(jobject obj, int intf_id_hash, void *intf_id,
10 | int method_index);
11 |
12 | struct idv_ht_node {
13 | idv_ht_node *next;
14 | void *intf_id;
15 | void *idv;
16 | };
17 |
18 | } // extern "C"
19 |
20 | // The hash table of interface dispatch vectors.
21 | // representation type is actually a linked list
22 | class idv_ht {
23 | public:
24 | /**
25 | * Constructor.
26 | * @param capacity must be a power of 2
27 | */
28 | idv_ht(size_t capacity);
29 |
30 | /**
31 | * Fetch an interface dispatch vector with its precomputed hash
32 | * code.
33 | */
34 | void *get(int hashcode, void *intf_id);
35 |
36 | /**
37 | * Add an interface dispatch vector with its precomputed hash
38 | * code.
39 | */
40 | void put(int hashcode, void *intf_id, void *idv);
41 |
42 | private:
43 | idv_ht_node **table;
44 | size_t capacity;
45 | size_t getIndexForHash(int h);
46 | };
47 |
--------------------------------------------------------------------------------
/runtime/native/monitor.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2019 Cornell University
2 |
3 | #pragma once
4 |
5 | #include
6 | #include
7 | #include
8 | #include
9 |
10 | #define GC_THREADS
11 | #include
12 | #undef GC_THREADS
13 |
14 | class Monitor {
15 | public:
16 | Monitor(const Monitor &monitor) = delete;
17 | Monitor &operator=(const Monitor &monitor) = delete;
18 |
19 | static Monitor &Instance();
20 | void enter(jobject obj);
21 | void exit(jobject obj);
22 |
23 | void wait(jobject obj, jlong ms);
24 | void notify(jobject obj);
25 | void notifyAll(jobject obj);
26 |
27 | pthread_mutex_t *globalMutex();
28 |
29 | private:
30 | static thread_local std::deque syncObjs;
31 | pthread_mutex_t mutex;
32 |
33 | Monitor();
34 | bool hasEntered(jobject obj);
35 | };
36 |
37 | class ScopedLock {
38 | private:
39 | pthread_mutex_t *mutex;
40 |
41 | public:
42 | ScopedLock(pthread_mutex_t *_mutex);
43 | ~ScopedLock();
44 | };
--------------------------------------------------------------------------------
/runtime/native/nativetest.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #include "nativetest.h"
4 |
5 | extern "C" {
6 | JNIEXPORT jstring JNICALL Java_NativeTest_getNativeStringTest(JNIEnv *env,
7 | jclass ignored) {
8 | jstring jkey = env->NewStringUTF("testNativeCall");
9 | return jkey;
10 | }
11 |
12 | JNIEXPORT jstring JNICALL
13 | Java_NativeTest_00024NativeTestInner_getNativeInnerStringTest(JNIEnv *env,
14 | jobject ignored) {
15 | jstring jkey = env->NewStringUTF("testInnerNativeCall");
16 | return jkey;
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/runtime/native/nativetest.h:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | /* DO NOT EDIT THIS FILE - it is machine generated */
4 | #include
5 | /* Header for class NativeTest */
6 |
7 | #ifndef _Included_NativeTest
8 | #define _Included_NativeTest
9 | #ifdef __cplusplus
10 | extern "C" {
11 | #endif
12 | /*
13 | * Class: NativeTest
14 | * Method: getNativeStringTest
15 | * Signature: ()Ljava/lang/String;
16 | */
17 | JNIEXPORT jstring JNICALL Java_NativeTest_getNativeStringTest
18 | (JNIEnv *, jclass);
19 |
20 | /*
21 | * Class: NativeTest_NativeTestInner
22 | * Method: getNativeInnerStringTest
23 | * Signature: ()Ljava/lang/String;
24 | */
25 | JNIEXPORT jstring JNICALL Java_NativeTest_00024NativeTestInner_getNativeInnerStringTest
26 | (JNIEnv *, jobject);
27 |
28 |
29 | #ifdef __cplusplus
30 | }
31 | #endif
32 | #endif
33 |
--------------------------------------------------------------------------------
/runtime/native/reflect.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #include "reflect.h"
4 |
5 | extern "C" {
6 |
7 | void CTOR_CTOR(jclass, jobjectArray, jobjectArray, jint, jint, jstring,
8 | jbyteArray, jbyteArray);
9 |
10 | bool InstanceOf(jobject obj, void *type_id) {
11 | if (obj == nullptr)
12 | return false;
13 | type_info *type_info = Unwrap(obj)->Cdv()->SuperTypes();
14 | for (int32_t i = 0, end = type_info->size; i < end; ++i)
15 | if (type_info->super_type_ids[i] == type_id)
16 | return true;
17 | return false;
18 | }
19 | } // extern "C"
20 |
21 | jobject CreateConstructor(jclass declaring_clazz,
22 | const JavaClassInfo *clazz_info,
23 | JavaMethodInfo ctor_info) {
24 | // TODO actually implement
25 | return NULL;
26 | }
27 |
--------------------------------------------------------------------------------
/runtime/native/reflect.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #pragma once
4 |
5 | #include "class.h"
6 | #include "factory.h"
7 | #include "rep.h"
8 | #include
9 | extern "C" {
10 | bool InstanceOf(jobject obj, void *compare_type_id);
11 | } // extern "C"
12 |
13 | jobject CreateConstructor(jclass declaring_clazz,
14 | const JavaClassInfo *clazz_info,
15 | JavaMethodInfo ctor_info);
16 |
--------------------------------------------------------------------------------
/runtime/native/stack_trace.cpp:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #include "stack_trace.h"
4 | #include
5 | #include
6 |
7 | void DumpStackTrace() {
8 | // Dump stack trace.
9 | constexpr int max_frames = 256;
10 | void *callstack[max_frames];
11 | int frames = backtrace(callstack, max_frames);
12 | backtrace_symbols_fd(callstack, frames, fileno(stderr));
13 | }
14 |
--------------------------------------------------------------------------------
/runtime/native/stack_trace.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2018 Cornell University
2 |
3 | #pragma once
4 |
5 | void DumpStackTrace();
6 |
--------------------------------------------------------------------------------
/runtime/native/threads.h:
--------------------------------------------------------------------------------
1 | // Copyright (C) 2019 Cornell University
2 |
3 | #include
4 | #include
5 | #include
6 | #include
7 |
8 | #define GC_THREADS
9 | #include
10 | #undef GC_THREADS
11 |
12 | extern thread_local jobject currentThread;
13 |
14 | struct NativeThread {
15 | pthread_t tid;
16 | bool threadStatus;
17 | bool interrupted;
18 | };
19 |
20 | class Threads {
21 | public:
22 | Threads(const Threads &threads) = delete;
23 | Threads &operator=(const Threads &threads) = delete;
24 | static Threads &Instance();
25 |
26 | void startThread(jobject jthread);
27 | void join();
28 | std::unordered_map threads;
29 |
30 | private:
31 | Threads() = default;
32 | };
33 |
34 | jobject GetMainThread();
35 |
--------------------------------------------------------------------------------
/runtime/runtime.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/runtime/src/jlang/runtime/BaseClass.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.runtime;
4 |
5 | // This is an empty class whose Class Object.
6 | // We'll use as the basis for all primitive.class objects.
7 | // e.g. int.class
8 | class BaseClass {
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/runtime/src/jlang/runtime/Constants.java:
--------------------------------------------------------------------------------
1 | package jlang.runtime;
2 |
3 | public class Constants {
4 | // TODO: auto-generate
5 | public static final int classSize = 168; // = v.obj.sizeOfObj(v.ts.Class())
6 | public static final int numOfRuntimeCdvArrayMethods = 11; // = v.cdvMethods(v.ts.ArrayObject()).size()
7 | }
8 |
--------------------------------------------------------------------------------
/runtime/src/jlang/runtime/Exceptions.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.runtime;
4 | import java.lang.reflect.Constructor;
5 |
6 | class Exceptions {
7 |
8 | static void createClassNotFoundException(String name) throws ClassNotFoundException { throw new ClassNotFoundException(name) ; }
9 | static void throwNewThrowable(Class extends Throwable> clazz, String msg) throws Throwable {
10 | Constructor extends Throwable> ctor = clazz.getConstructor(String.class);
11 | throw ctor.newInstance(msg);
12 | }
13 | static void throwThrowable(Throwable t) throws Throwable {
14 | throw t;
15 | }
16 | static void throwInterruptedException() throws InterruptedException { throw new InterruptedException(); }
17 | }
18 |
--------------------------------------------------------------------------------
/runtime/src/jlang/runtime/Factory.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.runtime;
4 |
5 | // Helps native code construct common Java objects.
6 | class Factory {
7 |
8 | static boolean[] BooleanArray (int len) { return new boolean[len]; }
9 | static byte [] ByteArray (int len) { return new byte [len]; }
10 | static char [] CharArray (int len) { return new char [len]; }
11 | static short [] ShortArray (int len) { return new short [len]; }
12 | static int [] IntArray (int len) { return new int [len]; }
13 | static long [] LongArray (int len) { return new long [len]; }
14 | static float [] FloatArray (int len) { return new float [len]; }
15 | static double [] DoubleArray (int len) { return new double [len]; }
16 |
17 | static String String(char[] chars) { return new String(chars); }
18 |
19 | static Object[] ObjectArray(int len) {
20 | return new Object[len];
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/runtime/src/jlang/runtime/Helper.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.runtime;
4 |
5 | // Helper functions that implement Java semantics so that the compiler
6 | // doesn't have to. That is, a JLang translation can sometimes call one of
7 | // these helper methods rather than translating everything directly.
8 | class Helper {
9 |
10 | // If o or o.toString() are null, we must substitute "null".
11 | static String toString(Object o) {
12 | if (o == null) return "null";
13 | String res = o.toString();
14 | return res == null ? "null" : res;
15 | }
16 |
17 | static void arrayStore(Object[] arr, int i, Object o) {
18 | arr[i] = o;
19 | }
20 |
21 | static Object arrayLoad(Object[] arr, int i) {
22 | return arr[i];
23 | }
24 |
25 | static Integer autoBoxInt(int i) {
26 | return new Integer(i);
27 | }
28 |
29 | static void printString(String s) {
30 | System.out.println(s);
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/runtime/src/jlang/runtime/MainWrapper.java:
--------------------------------------------------------------------------------
1 | //Copyright (C) 2018 Cornell University
2 |
3 | package jlang.runtime;
4 |
5 | // Wraps the Java entry point in a try-catch block so that we can
6 | // report uncaught exceptions to the client.
7 | class MainWrapper {
8 |
9 | // This native method is generated by JLang when it encounters
10 | // the main method in the client program.
11 | static native void main(String[] args);
12 |
13 | static void runMain(String[] args) {
14 | // TODO: Print stack trace.
15 | main(args);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/AnonymousSubClass.java:
--------------------------------------------------------------------------------
1 | import java.test.AbstractTest;
2 | import java.test.Test;
3 | import java.test.SubTest;
4 |
5 | public class AnonymousSubClass {
6 |
7 | public static void main(String[] args) {
8 | AbstractTest at = new Test();
9 | at.printMessage();
10 | at = new SubTest();
11 | at.printMessage();
12 | SubTest st = new SubTest() {
13 | public void doNothing(){ System.out.print(""); };
14 | };
15 | st.printMessage();
16 |
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/isolated/.gitignore:
--------------------------------------------------------------------------------
1 | *.sol
2 | *.ll
3 | *.output
4 | *.binary
5 | /Tmp.java
6 | *.dSYM
7 |
--------------------------------------------------------------------------------
/tests/isolated/Add.java:
--------------------------------------------------------------------------------
1 | public class Add {
2 | static {
3 | System.out.println("Static initializer");
4 | }
5 |
6 |
7 | public static void main(String[] args) {
8 | Add add = new Add(); // Runs static initializer.
9 | // String s = args[1];
10 | f(1);
11 | }
12 |
13 | public static int f(int i) {
14 | System.out.println("Hello!");
15 | char c = 1;
16 | short s = 2;
17 | if (i < 2 && i > -10) {
18 | if (i < 3) {
19 | return 3;
20 | } else {
21 | return 4;
22 | }
23 | }
24 | i += i;
25 | i = (int) (1 + 2l);
26 | long j = i;
27 | return c + s;
28 | }
29 |
30 | public static native int g();
31 | }
32 |
--------------------------------------------------------------------------------
/tests/isolated/Annotations.java:
--------------------------------------------------------------------------------
1 | class Annotations {
2 |
3 | enum T {T1, T2}
4 |
5 | @Target(T.T1)
6 | public @interface Target {
7 | T[] value();
8 | }
9 |
10 | @Target({T.T1, T.T2})
11 | public @interface A {}
12 |
13 | @A
14 | void f() {}
15 |
16 | public static void main(String[] arg) {
17 | System.out.println("begin");
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/tests/isolated/AnonymousClass.java:
--------------------------------------------------------------------------------
1 | public class AnonymousClass {
2 | private final String field = "outer field";
3 |
4 | private interface I {
5 | void f();
6 | }
7 |
8 | void member() {
9 | final int local = 42;
10 | I i = new I() {
11 | private final String field = "inner field";
12 |
13 | @Override
14 | public void f() {
15 | System.out.println(AnonymousClass.this.field);
16 | System.out.println(field);
17 | System.out.println(local);
18 | }
19 | };
20 | i.f();
21 | }
22 |
23 | public static void main(String[] args) {
24 | final String local = "local";
25 |
26 | I i = new I() {
27 | int field = 3;
28 |
29 | @Override
30 | public void f() {
31 | System.out.println(local);
32 | System.out.println(field);
33 |
34 | I j = new I() {
35 | int field = 4;
36 |
37 | @Override
38 | public void f() {
39 | System.out.println(local);
40 | System.out.println(field);
41 | }
42 | };
43 | j.f();
44 | }
45 | };
46 | i.f();
47 |
48 | i = new I() { public void f() { System.out.println(5); } };
49 | i.f();
50 |
51 | new AnonymousClass().member();
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/tests/isolated/ArrayOutOfBounds.java:
--------------------------------------------------------------------------------
1 | public class ArrayOutOfBounds {
2 | public static void main(String[] args) {
3 | int[] xs = {0,1,2,3,4};
4 | try {
5 | for (int i = 0; i <= xs.length + 10; i++) {
6 | System.out.println(xs[i]);
7 | }
8 | } catch (ArrayIndexOutOfBoundsException e) {
9 | System.out.println("catch");
10 | }
11 |
12 | try {
13 | for (int i = 0; i <= xs.length + 10; i++) {
14 | System.out.println(xs[i] = i+10);
15 | }
16 | } catch (ArrayIndexOutOfBoundsException e){
17 | System.out.println("catch") ;
18 | }
19 |
20 | int x = 0;
21 | try {
22 | System.out.println(xs[--x]);
23 | } catch (ArrayIndexOutOfBoundsException e) {
24 | System.out.println("catch " + x);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/tests/isolated/Assert.java:
--------------------------------------------------------------------------------
1 | class Assert {
2 |
3 | public static void main(String[] args) {
4 | try {
5 | assert true;
6 | System.out.println("After1");
7 | } catch (AssertionError e) {
8 | System.out.println("Bad");
9 | }
10 | try {
11 | assert false;
12 | System.out.println("After2");
13 | } catch (AssertionError e) {
14 | System.out.println("Good");
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/tests/isolated/BinaryCondOps.java:
--------------------------------------------------------------------------------
1 | public class BinaryCondOps {
2 | public static void main(String[] args) {
3 | boolean x = false && printMsgTrue();
4 | assertBool(!x);
5 | x = false && printMsgFalse();
6 | assertBool(!x);
7 |
8 | x = true && printMsgTrue();
9 | assertBool(x);
10 | x = true && printMsgFalse();
11 | assertBool(!x);
12 |
13 | x = false || printMsgTrue();
14 | assertBool(x);
15 | x = false || printMsgFalse();
16 | assertBool(!x);
17 |
18 | x = true || printMsgTrue();
19 | assertBool(x);
20 | x = true || printMsgFalse();
21 | assertBool(x);
22 | }
23 |
24 | static void assertBool(boolean x){
25 | if (x){
26 | System.out.println("GOOD");
27 | } else {
28 | System.out.println("FAIL");
29 | }
30 | }
31 |
32 |
33 | static boolean printMsgTrue(){
34 | System.out.println("MSG");
35 | return true;
36 | }
37 |
38 | static boolean printMsgFalse(){
39 | System.out.println("MSG");
40 | return false;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/tests/isolated/Blocks.java:
--------------------------------------------------------------------------------
1 | public class Blocks {
2 | public static void main(String[] args) {
3 | {
4 | System.out.print(1);
5 | }
6 | {
7 | System.out.print(2);
8 | }
9 | {
10 | {
11 | System.out.print(3);
12 | }
13 | {
14 | System.out.print(4);
15 |
16 | }
17 | }
18 | }
19 |
20 | }
21 |
--------------------------------------------------------------------------------
/tests/isolated/Cast.java:
--------------------------------------------------------------------------------
1 | class Cast {
2 |
3 | static Object f() {
4 | return "Hello, world!";
5 | }
6 |
7 | static String g() {
8 | return (String) new Object();
9 | }
10 |
11 | static class Inner {
12 | T field;
13 | Inner(T field) {
14 | this.field = field;
15 | }
16 | }
17 |
18 | public static void main(String[] args) {
19 | System.out.println("begin");
20 |
21 | String s = (String) f();
22 | System.out.println(s);
23 |
24 | try { g(); }
25 | catch (ClassCastException e) {
26 | System.out.println("catch g");
27 | }
28 |
29 | Inner i = new Inner(new Integer(42));
30 | System.out.println(i.field);
31 | System.out.println((Integer) i.field);
32 | try {
33 | System.out.println((String) (Object) i.field);
34 | } catch (ClassCastException e) {
35 | System.out.println("catch field");
36 | }
37 |
38 | System.out.println((Integer) 42);
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/tests/isolated/CastNull.java:
--------------------------------------------------------------------------------
1 | class CastNull {
2 |
3 | static class InnerOne {
4 |
5 | }
6 |
7 | static interface InnerInterOne {
8 | public Object objectify();
9 | }
10 |
11 | static class InnerTwo implements InnerInterOne {
12 | public Object objectify() {
13 | return this;
14 | }
15 |
16 |
17 | }
18 |
19 | static class InnerThree implements InnerInterOne {
20 | public Object objectify() {
21 | return null;
22 | }
23 | }
24 |
25 | public static void main(String[] args) {
26 |
27 | InnerTwo t = null;
28 | System.out.println(t == null);
29 | t = new InnerTwo();
30 | InnerInterOne in = (InnerInterOne)t.objectify();
31 | System.out.println(in == null);
32 | in = (InnerInterOne) new InnerThree().objectify();
33 | System.out.println(in == null);
34 | InnerOne ino = (InnerOne) new InnerThree().objectify();
35 | System.out.println(ino == null);
36 | try {
37 | Object o = new InnerTwo();
38 | InnerOne o1 = (InnerOne) new InnerTwo().objectify();
39 | } catch (ClassCastException e) {
40 | System.out.println("caught exception");
41 | }
42 | }
43 |
44 | }
--------------------------------------------------------------------------------
/tests/isolated/ClassLiteral.java:
--------------------------------------------------------------------------------
1 | class ClassLiteral {
2 |
3 | class Inner {}
4 |
5 | interface It {}
6 |
7 | abstract class Abstract {}
8 |
9 | public static void main(String[] args) {
10 | System.out.println(int.class);
11 | System.out.println(ClassLiteral.Inner.class);
12 | System.out.println(Object.class.toString());
13 | System.out.println(byte[].class);
14 | System.out.println(String[][].class);
15 | System.out.println();
16 |
17 | System.out.println(new ClassLiteral().getClass());
18 | System.out.println(new Object().getClass());
19 | System.out.println("String".getClass());
20 | // System.out.println(new char[0].getClass()); // TODO
21 | System.out.println();
22 |
23 | System.out.println(Object.class == new Object().getClass());
24 | System.out.println(String.class == "String".getClass());
25 | System.out.println(String.class == new Object().getClass());
26 | System.out.println(ClassLiteral.Inner.class
27 | == new ClassLiteral().new Inner().getClass());
28 | // System.out.println(It.class); TODO
29 | System.out.println(Abstract.class);
30 | // System.out.println(short[].class == new short[] {1, 2, 3}.getClass()); TODO
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/isolated/ClassReflection.java:
--------------------------------------------------------------------------------
1 | import java.lang.reflect.Field;
2 |
3 | class ClassReflection {
4 |
5 | public static void main(String[] args) {
6 | ClassReflectionE ce = new ClassReflectionE();
7 | Class clse = ce.getClass();
8 | Field[] fe = clse.getDeclaredFields();
9 | System.out.println(fe.length);
10 | System.out.println(clse.getSuperclass());
11 | }
12 |
13 | int k;
14 |
15 | public ClassReflection(int i, int j) {
16 | k = i + j;
17 | }
18 |
19 | static class GenericClassReflection {
20 | T[] arr;
21 |
22 | public T get(){
23 | return arr[0];
24 | }
25 | }
26 |
27 | static class ClassReflectionE extends ClassReflection {
28 | public int gg;
29 |
30 | public ClassReflectionE() {
31 | super(641,42);
32 | }
33 | }
34 | }
--------------------------------------------------------------------------------
/tests/isolated/ClassTest.java:
--------------------------------------------------------------------------------
1 | public class ClassTest {
2 |
3 | public static void main(String[] args) throws Exception {
4 | // Class> clazz = Class.forName("java.lang.Object");
5 | System.out.println(Object.class.getName());
6 | }
7 | }
--------------------------------------------------------------------------------
/tests/isolated/Conditional.java:
--------------------------------------------------------------------------------
1 | class Conditional {
2 |
3 | static boolean t() {
4 | System.out.println("t");
5 | return true;
6 | }
7 |
8 | static boolean f() {
9 | System.out.println("f");
10 | return false;
11 | }
12 |
13 | static int a() {
14 | System.out.println("a");
15 | return 1;
16 | }
17 |
18 | static int b() {
19 | System.out.println("b");
20 | return 2;
21 | }
22 |
23 | public static void main(String[] args) {
24 | System.out.println("begin");
25 | System.out.println(true ? 1 : 2);
26 | System.out.println(false ? 1 : 2);
27 | System.out.println(t() ? a() : b());
28 | System.out.println(f() ? a() : b());
29 | }
30 | }
--------------------------------------------------------------------------------
/tests/isolated/Empty.java:
--------------------------------------------------------------------------------
1 | public class Empty {
2 | public static void main(String[] args) {
3 | // Do nothing.
4 | }
5 | }
6 |
--------------------------------------------------------------------------------
/tests/isolated/ExceptionsNested.java:
--------------------------------------------------------------------------------
1 | class ExceptionsNested {
2 | public static void main(String[] args) {
3 | try {
4 | catchesRuntimeExn();
5 | System.out.println("Should not print");
6 | } catch (Exception e) {
7 | System.out.println("Caught exception");
8 | }
9 | }
10 |
11 | public static void catchesRuntimeExn() throws Exception {
12 | try {
13 | throwsExn();
14 | } catch (RuntimeException e) {
15 | System.out.println("Caught runtime exception");
16 | }
17 | }
18 |
19 | public static void throwsExn() throws Exception {
20 | throw new Exception();
21 | }
22 | }
--------------------------------------------------------------------------------
/tests/isolated/Generic.java:
--------------------------------------------------------------------------------
1 | public class Generic{
2 | public static void main(String[] args) {
3 | System.out.println(new Generic("Hi There!").toString());
4 | System.out.println(new Generic