Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gluon-bot committed Sep 28, 2023
2 parents 9ef6aa5 + 58ca6d4 commit eef0e99
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@

import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeClass;
import org.graalvm.compiler.graph.iterators.NodePredicates;
import org.graalvm.compiler.nodeinfo.NodeInfo;
import org.graalvm.compiler.nodes.AbstractBeginNode;
import org.graalvm.compiler.nodes.BeginNode;
import org.graalvm.compiler.nodes.BeginStateSplitNode;
import org.graalvm.compiler.nodes.LoopExitNode;
import org.graalvm.compiler.nodes.MemoryProxyNode;
import org.graalvm.compiler.nodes.ValueProxyNode;
import org.graalvm.compiler.nodes.spi.Canonicalizable;
import org.graalvm.compiler.nodes.spi.CanonicalizerTool;

Expand Down Expand Up @@ -61,4 +65,17 @@ public Node canonical(CanonicalizerTool tool) {
}
return this;
}

@Override
public boolean verify() {
if (predecessor() instanceof LoopExitNode loopExit) {
/*
* Must guarantee only value and memory proxies are attached to the loop exit. Anything
* else should be attached to this node
*/
assert loopExit.usages().stream().allMatch(NodePredicates.isA(ValueProxyNode.class).or(MemoryProxyNode.class)) : String.format("LoopExit has disallowed usages %s", loopExit);
}

return super.verify();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
import org.graalvm.compiler.nodes.calc.IntegerEqualsNode;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.cfg.HIRBlock;
import org.graalvm.compiler.nodes.extended.CaptureStateBeginNode;
import org.graalvm.compiler.nodes.extended.GuardingNode;
import org.graalvm.compiler.nodes.extended.IntegerSwitchNode;
import org.graalvm.compiler.nodes.extended.LoadHubNode;
Expand Down Expand Up @@ -226,11 +227,46 @@ public static class MoveGuardsUpwards implements ControlFlowGraph.RecursiveVisit

HIRBlock anchorBlock;

/**
* Guards cannot be moved above CaptureStateBeginNodes in order to ensure deoptimizations
* are always attached to valid FrameStates.
*/
private static boolean disallowUpwardGuardMovement(HIRBlock b) {
return b.getBeginNode() instanceof CaptureStateBeginNode;
}

@Override
@SuppressWarnings("try")
public HIRBlock enter(HIRBlock b) {
HIRBlock oldAnchorBlock = anchorBlock;
if (b.getDominator() == null || b.getDominator().getPostdominator() != b) {
/*
* The goal of this pass is to move guards upward while not introducing the guards on
* new paths. At all points the anchorBlock must set so the following two invariants
* hold:
*
* (1) The anchorBlock dominates the current block.
*
* (2) The current block post-dominates the anchorBlock.
*
* Note blocks are traversed in dominator tree order.
*
* anchorBlock must be set to the current block if:
*
* (1) The current block does not have a dominator (i.e., this is the start of a new
* dominator tree walk).
*
* (2) The immediate dominator of current block is not post-dominated by this block. Due
* to using a dominator tree traversal, this is equivalent to ensuring the current block
* post-dominates the anchorBlock.
*
* (3) Guards are not allowed to move above this block. The can happen when dominator
* blocks can have invalid FrameStates, such as when the block start is a
* CaptureStateBeginNode.
*/
boolean updateAnchorBlock = b.getDominator() == null ||
b.getDominator().getPostdominator() != b ||
disallowUpwardGuardMovement(b);
if (updateAnchorBlock) {
// New anchor.
anchorBlock = b;
}
Expand Down Expand Up @@ -271,52 +307,51 @@ public HIRBlock enter(HIRBlock b) {
* successors are loop exits, even of potentially different loops. Thus, we need
* to ensure we see all possible loop exits involved for all loops.
*/
LoopExitNode trueSuccLex = trueSuccessor instanceof LoopExitNode ? (LoopExitNode) trueSuccessor : null;
LoopExitNode falseSuccLex = falseSuccessor instanceof LoopExitNode ? (LoopExitNode) falseSuccessor : null;
EconomicSet<LoopExitNode> allLoopsAllExits = null;
if (trueSuccLex != null) {
if (trueSuccessor instanceof LoopExitNode successor) {
if (allLoopsAllExits == null) {
allLoopsAllExits = EconomicSet.create();
}
allLoopsAllExits.addAll(trueSuccLex.loopBegin().loopExits());
allLoopsAllExits.remove(trueSuccLex);
allLoopsAllExits.addAll(successor.loopBegin().loopExits());
allLoopsAllExits.remove(successor);
}
if (falseSuccLex != null) {
if (falseSuccessor instanceof LoopExitNode successor) {
if (allLoopsAllExits == null) {
allLoopsAllExits = EconomicSet.create();
}
allLoopsAllExits.addAll(falseSuccLex.loopBegin().loopExits());
allLoopsAllExits.remove(falseSuccLex);
allLoopsAllExits.addAll(successor.loopBegin().loopExits());
allLoopsAllExits.remove(successor);
}
if (allLoopsAllExits == null || allLoopsAllExits.isEmpty()) {
for (GuardNode guard : falseSuccessor.guards().snapshot()) {
GuardNode otherGuard = trueGuards.get(guard.getCondition());
if (otherGuard != null && guard.isNegated() == otherGuard.isNegated()) {
Speculation speculation = otherGuard.getSpeculation();
for (GuardNode falseGuard : falseSuccessor.guards().snapshot()) {
GuardNode trueGuard = trueGuards.get(falseGuard.getCondition());
if (trueGuard != null && falseGuard.isNegated() == trueGuard.isNegated()) {
Speculation speculation = trueGuard.getSpeculation();
if (speculation == null) {
speculation = guard.getSpeculation();
} else if (guard.getSpeculation() != null && guard.getSpeculation() != speculation) {
speculation = falseGuard.getSpeculation();
} else if (falseGuard.getSpeculation() != null && falseGuard.getSpeculation() != speculation) {
// Cannot optimize due to different speculations.
continue;
}
try (DebugCloseable closeable = guard.withNodeSourcePosition()) {
StructuredGraph graph = guard.graph();
GuardNode newlyCreatedGuard = new GuardNode(guard.getCondition(), anchorBlock.getBeginNode(), guard.getReason(), guard.getAction(), guard.isNegated(), speculation,
guard.getNoDeoptSuccessorPosition());
try (DebugCloseable closeable = falseGuard.withNodeSourcePosition()) {
StructuredGraph graph = falseGuard.graph();
GuardNode newlyCreatedGuard = new GuardNode(falseGuard.getCondition(), anchorBlock.getBeginNode(), falseGuard.getReason(), falseGuard.getAction(),
falseGuard.isNegated(), speculation,
falseGuard.getNoDeoptSuccessorPosition());
GuardNode newGuard = node.graph().unique(newlyCreatedGuard);
if (otherGuard.isAlive()) {
if (trueGuard.isAlive()) {
if (trueSuccessor instanceof LoopExitNode && beginNode.graph().isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL)) {
otherGuard.replaceAndDelete(ProxyNode.forGuard(newGuard, (LoopExitNode) trueSuccessor));
trueGuard.replaceAndDelete(ProxyNode.forGuard(newGuard, (LoopExitNode) trueSuccessor));
} else {
otherGuard.replaceAndDelete(newGuard);
trueGuard.replaceAndDelete(newGuard);
}
}
if (falseSuccessor instanceof LoopExitNode && beginNode.graph().isBeforeStage(StageFlag.VALUE_PROXY_REMOVAL)) {
guard.replaceAndDelete(ProxyNode.forGuard(newGuard, (LoopExitNode) falseSuccessor));
falseGuard.replaceAndDelete(ProxyNode.forGuard(newGuard, (LoopExitNode) falseSuccessor));
} else {
guard.replaceAndDelete(newGuard);
falseGuard.replaceAndDelete(newGuard);
}
graph.getOptimizationLog().report(ConditionalEliminationPhase.class, "GuardCombination", guard);
graph.getOptimizationLog().report(ConditionalEliminationPhase.class, "GuardCombination", falseGuard);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,43 +184,43 @@ protected NodeStateAssignment merge(AbstractMergeNode merge, List<NodeStateAssig
* in its return values. If such a snippet is encountered the subsequent logic will
* assign an invalid state to the merge.
*/
NodeStateAssignment bci = null;
NodeStateAssignment mergeAssignment = null;
forAllStates: for (int i = 0; i < states.size(); i++) {
NodeStateAssignment assignment = states.get(i);
switch (assignment) {
case BEFORE_BCI:
/* If we only see BEFORE_BCI, the result will be BEFORE_BCI. */
if (bci == null) {
bci = NodeStateAssignment.BEFORE_BCI;
if (mergeAssignment == null) {
mergeAssignment = NodeStateAssignment.BEFORE_BCI;
}
break;
case AFTER_BCI:
case AFTER_BCI_INVALID_FOR_DEOPTIMIZATION:
/* If we see at least one kind of AFTER_BCI, the result will be the same. */
if (bci == NodeStateAssignment.AFTER_BCI || bci == NodeStateAssignment.AFTER_BCI_INVALID_FOR_DEOPTIMIZATION) {
GraalError.guarantee(bci == assignment, "Cannot mix valid and invalid AFTER_BCI versions");
if (mergeAssignment == NodeStateAssignment.AFTER_BCI || mergeAssignment == NodeStateAssignment.AFTER_BCI_INVALID_FOR_DEOPTIMIZATION) {
GraalError.guarantee(mergeAssignment == assignment, "Cannot mix valid and invalid AFTER_BCI versions");
}
bci = assignment;
mergeAssignment = assignment;
break;
case AFTER_EXCEPTION_BCI:
/* AFTER_EXCEPTION_BCI can only be merged with itself. */
if (bci == null || bci == NodeStateAssignment.AFTER_EXCEPTION_BCI) {
bci = NodeStateAssignment.AFTER_EXCEPTION_BCI;
if (mergeAssignment == null || mergeAssignment == NodeStateAssignment.AFTER_EXCEPTION_BCI) {
mergeAssignment = NodeStateAssignment.AFTER_EXCEPTION_BCI;
break;
}
/* Cannot merge AFTER_EXCEPTION_BCI with anything else. */
bci = NodeStateAssignment.INVALID;
mergeAssignment = NodeStateAssignment.INVALID;
break forAllStates;
case INVALID:
bci = NodeStateAssignment.INVALID;
mergeAssignment = NodeStateAssignment.INVALID;
break forAllStates;
default:
throw GraalError.shouldNotReachHere("Unhandled node state assignment: " + assignment + " at merge " + merge); // ExcludeFromJacocoGeneratedReport
}
}
assert bci != null;
stateMapping.put(merge, bci);
return bci;
assert mergeAssignment != null;
stateMapping.put(merge, mergeAssignment);
return mergeAssignment;
}

@Override
Expand Down
17 changes: 9 additions & 8 deletions docs/getting-started/graalvm-community/macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,25 @@ Note that on macOS the JDK installation path is: _/Library/Java/JavaVirtualMachi
Follow these steps to install GraalVM:

1. Navigate to the [GraalVM Downloads page](https://www.graalvm.org/downloads/). Select **21** for the Java version, **macOS** for the operating system, **x64** or **aarch64** for the architecture, and download.

2. Remove the quarantine attribute (required for macOS Catalina and later):
```shell
sudo xattr -r -d com.apple.quarantine graalvm-jdk-<version>_macos-<architecture>.tar.gz
```

2. Unzip the archive.
3. Unzip the archive.
```shell
tar -xzf graalvm-jdk-<version>_macos-<architecture>.tar.gz
```
Alternatively, open the file in Finder.
> Note: If you are using macOS Catalina and later you may need to remove the quarantine attribute:
```shell
sudo xattr -r -d com.apple.quarantine /path/to/graalvm
```

3. Move the downloaded package to its proper location, the `/Library/Java/JavaVirtualMachines` directory. Since this is a system directory, `sudo` is required:
4. Move the downloaded package to its proper location, the `/Library/Java/JavaVirtualMachines` directory. Since this is a system directory, `sudo` is required:
```shell
sudo mv graalvm-jdk-<version>_macos-<architecture> /Library/Java/JavaVirtualMachines
```
To verify if the move is successful and to get a list of all installed JDKs, run `/usr/libexec/java_home -V`.

4. There can be multiple JDKs installed on the machine. The next step is to configure the runtime environment:
5. There can be multiple JDKs installed on the machine. The next step is to configure the runtime environment:
- Set the `JAVA_HOME` environment variable to resolve to the GraalVM installation directory:
```shell
export JAVA_HOME=/Library/Java/JavaVirtualMachines/<graalvm>/Contents/Home
Expand All @@ -41,7 +42,7 @@ Follow these steps to install GraalVM:
export PATH=/Library/Java/JavaVirtualMachines/<graalvm>/Contents/Home/bin:$PATH
```

5. To check whether the installation was successful, run the `java -version` command.
6. To check whether the installation was successful, run the `java -version` command.

Optionally, you can specify GraalVM as the default JRE or JDK installation in your Java IDE.

Expand Down
20 changes: 10 additions & 10 deletions docs/getting-started/graalvm-enterprise/macos.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ Note that in macOS, the JDK installation path is: _/Library/Java/JavaVirtualMach

Follow these steps to install Oracle GraalVM:

1. Navigate to [Oracle Java Downloads](https://www.oracle.com/java/technologies/downloads/).
Select the preferred Oracle GraalVM version, **21** for the Java version, **macOS** for the operating system, and the architecture. Start downloading.
1. Navigate to [Oracle Java Downloads](https://www.oracle.com/java/technologies/downloads/). Select the preferred Oracle GraalVM version, **21** for the Java version, **macOS** for the operating system, and the architecture. Start downloading.

2. Unzip the archive:
2. Remove the quarantine attribute (required for macOS Catalina and later):
```shell
sudo xattr -r -d com.apple.quarantine graalvm-jdk-<version>_macos-<architecture>.tar.gz
```

3. Unzip the archive:
```shell
tar -xzf graalvm-jdk-<version>_macos-<architecture>.tar.gz
```
Alternatively, open the file in the Finder.
> Note: If you are using macOS Catalina and later you may need to remove the quarantine attribute:
```shell
sudo xattr -r -d com.apple.quarantine /path/to/graalvm
```

3. Move the downloaded package to its proper location, the _/Library/Java/JavaVirtualMachines_ directory. Since this is a system directory, `sudo` is required:
4. Move the downloaded package to its proper location, the _/Library/Java/JavaVirtualMachines_ directory. Since this is a system directory, `sudo` is required:
```shell
sudo mv graalvm-jdk-<version>_macos-<architecture> /Library/Java/JavaVirtualMachines
```
To verify if the move is successful and to get a list of all installed JDKs, run `/usr/libexec/java_home -V`.

4. There can be multiple JDKs installed on the machine. The next step is to configure the runtime environment:
5. There can be multiple JDKs installed on the machine. The next step is to configure the runtime environment:
- Set the `JAVA_HOME` environment variable to resolve to the installation directory:
```shell
export JAVA_HOME=/Library/Java/JavaVirtualMachines/<graalvm>/Contents/Home
Expand All @@ -39,7 +39,7 @@ Select the preferred Oracle GraalVM version, **21** for the Java version, **macO
```shell
export PATH=/Library/Java/JavaVirtualMachines/<graalvm>/Contents/Home/bin:$PATH
```
5. To check whether the installation was successful, run the `java -version` command.
6. To check whether the installation was successful, run the `java -version` command.

Optionally, you can specify Oracle GraalVM as the default JRE or JDK installation in your Java IDE.

Expand Down
14 changes: 8 additions & 6 deletions docs/reference-manual/java-on-truffle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ You can download a standalone based on Oracle GraalVM or GraalVM Community Editi
* [Windows x64](https://gds.oracle.com/api/20220101/artifacts/04F488A062484081E0631818000A781E/content)

2. Unzip the archive:
```shell
tar -xzf <archive>.tar.gz
```
Alternatively, open the file in the Finder.
> Note: If you are using macOS Catalina and later you may need to remove the quarantine attribute:

> Note: If you are using macOS Catalina and later you may need to remove the quarantine attribute:
```shell
sudo xattr -r -d com.apple.quarantine <archive>.tar.gz
```


Extact:
```shell
tar -xzf <archive>.tar.gz
```

3. A standalone comes with a JVM in addition to its native launcher. Check the version to see the Java on Truffle runtime is active:
```shell
./path/to/bin/java -truffle --version
Expand Down
12 changes: 7 additions & 5 deletions docs/reference-manual/llvm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,16 @@ You can download a standalone based on Oracle GraalVM or GraalVM Community Editi
* [Windows x64](https://gds.oracle.com/api/20220101/artifacts/04F556B005683A58E0631818000A322D/content)

2. Unzip the archive:
```shell
tar -xzf <archive>.tar.gz
```
Alternatively, open the file in the Finder.
> Note: If you are using macOS Catalina and later you may need to remove the quarantine attribute:

> Note: If you are using macOS Catalina and later you may need to remove the quarantine attribute:
```shell
sudo xattr -r -d com.apple.quarantine <archive>.tar.gz
```

Extact:
```shell
tar -xzf <archive>.tar.gz
```

3. A standalone comes with a JVM in addition to its native launcher. Check the version to see GraalVM LLVM runtime is active:
```shell
Expand Down
Loading

0 comments on commit eef0e99

Please sign in to comment.