Skip to content

Commit

Permalink
synchronize class loading functions
Browse files Browse the repository at this point in the history
  • Loading branch information
guoyiteng committed Nov 23, 2019
1 parent 75ff4c5 commit b420616
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
6 changes: 6 additions & 0 deletions compiler/src/jlang/util/LLVMUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.stream.Collectors;
import java.util.stream.IntStream;

import static jlang.extension.JLangSynchronizedExt.buildMonitorFunc;
import static org.bytedeco.javacpp.LLVM.*;

/**
Expand Down Expand Up @@ -804,6 +805,9 @@ public LLVMValueRef buildGlobalCStr(String str) {

/** Emits a check to ensure that the given class has been loaded by the runtime. */
public void buildClassLoadCheck(ClassType ct) {
// Synchronize the class loading function.
buildMonitorFunc(v, Constants.MONITOR_ENTER, LLVMConstNull(v.utils.toLL(v.ts.Object())));

LLVMBasicBlockRef loadClass = v.utils.buildBlock("load.class");
LLVMBasicBlockRef end = v.utils.buildBlock("continue");
String classMangled = v.mangler.classObj(ct);
Expand All @@ -821,6 +825,8 @@ public void buildClassLoadCheck(ClassType ct) {
LLVMBuildBr(v.builder, end);

LLVMPositionBuilderAtEnd(v.builder, end);

buildMonitorFunc(v, Constants.MONITOR_EXIT, LLVMConstNull(v.utils.toLL(v.ts.Object())));
}

/**
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/jlang/visit/DesugarSynchronized.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ protected Node leaveDesugar(Node n) throws SemanticException {
// synchronized(o) {...}
// To
// {
// Object temp = o;
// try { MonitorEnter(o); ... }
// finally { MonitorExit(o); }
// Object syncObj = o;
// try { MonitorEnter(syncObj); ... }
// finally { MonitorExit(syncObj); }
// }
Synchronized node = (Synchronized) n;
Position pos = node.position();
Expand Down

0 comments on commit b420616

Please sign in to comment.