Skip to content

Commit 20afdfd

Browse files
jovanstevanovicRealCLanger
authored andcommitted
8273278: Support XSLT on GraalVM Native Image--deterministic bytecode generation in XSLT
Backport-of: f690a01f1e5de4ace39aefad656cb7c99f9ec4e1
1 parent cdd4075 commit 20afdfd

File tree

4 files changed

+23
-18
lines changed

4 files changed

+23
-18
lines changed

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/LiteralElement.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -33,6 +33,7 @@
3333
import com.sun.org.apache.xml.internal.serializer.ToHTMLStream;
3434
import java.util.ArrayList;
3535
import java.util.HashMap;
36+
import java.util.LinkedHashMap;
3637
import java.util.Hashtable;
3738
import java.util.List;
3839
import java.util.Map;
@@ -42,7 +43,7 @@
4243
* @author Jacek Ambroziak
4344
* @author Santiago Pericas-Geertsen
4445
* @author Morten Jorgensen
45-
* @LastModified: Oct 2017
46+
* @LastModified: Sep 2021
4647
*/
4748
final class LiteralElement extends Instruction {
4849

@@ -202,7 +203,7 @@ public Type typeCheck(SymbolTable stable) throws TypeCheckError {
202203
* to _ANY_ namespace URI. Used by literal result elements to determine
203204
*/
204205
public Set<Map.Entry<String, String>> getNamespaceScope(SyntaxTreeNode node) {
205-
Map<String, String> all = new HashMap<>();
206+
Map<String, String> all = new LinkedHashMap<>();
206207

207208
while (node != null) {
208209
Map<String, String> mapping = node.getPrefixMapping();

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Mode.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -48,6 +48,7 @@
4848
import com.sun.org.apache.xml.internal.dtm.DTM;
4949
import java.util.ArrayList;
5050
import java.util.HashMap;
51+
import java.util.LinkedHashMap;
5152
import java.util.Iterator;
5253
import java.util.List;
5354
import java.util.Map;
@@ -62,7 +63,7 @@
6263
* @author Morten Jorgensen
6364
* @author Erwin Bolwidt <ejb@klomp.org>
6465
* @author G. Todd Miller
65-
* @LastModified: Nov 2017
66+
* @LastModified: Sep 2021
6667
*/
6768
final class Mode implements Constants {
6869

@@ -129,13 +130,15 @@ final class Mode implements Constants {
129130

130131
/**
131132
* A mapping between templates and test sequences.
133+
* {@link LinkedHashMap} is necessary to make traversal order consistent across runs.
132134
*/
133-
private Map<Template, Object> _neededTemplates = new HashMap<>();
135+
private Map<Template, Object> _neededTemplates = new LinkedHashMap<>();
134136

135137
/**
136138
* A mapping between named templates and Mode objects.
139+
* {@link LinkedHashMap} is necessary to make traversal order consistent across runs.
137140
*/
138-
private Map<Template, Mode> _namedTemplates = new HashMap<>();
141+
private Map<Template, Mode> _namedTemplates = new LinkedHashMap<>();
139142

140143
/**
141144
* A mapping between templates and instruction handles.
@@ -198,7 +201,7 @@ public String functionName() {
198201

199202
public String functionName(int min, int max) {
200203
if (_importLevels == null) {
201-
_importLevels = new HashMap<>();
204+
_importLevels = new LinkedHashMap<>();
202205
}
203206
_importLevels.put(max, min);
204207
return _methodName + '_' + max;
@@ -1053,8 +1056,8 @@ public void compileApplyImports(ClassGenerator classGen, int min, int max) {
10531056
final List<String> names = xsltc.getNamesIndex();
10541057

10551058
// Clear some datastructures
1056-
_namedTemplates = new HashMap<>();
1057-
_neededTemplates = new HashMap<>();
1059+
_namedTemplates = new LinkedHashMap<>();
1060+
_neededTemplates = new LinkedHashMap<>();
10581061
_templateIHs = new HashMap<>();
10591062
_templateILs = new HashMap<>();
10601063
_patternGroups = (List<LocationPathPattern>[])new ArrayList[32];

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/Number.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -53,7 +53,7 @@
5353
/**
5454
* @author Jacek Ambroziak
5555
* @author Santiago Pericas-Geertsen
56-
* @LastModified: Nov 2017
56+
* @LastModified: Sep 2021
5757
*/
5858
final class Number extends Instruction implements Closure {
5959
private static final int LEVEL_SINGLE = 0;
@@ -383,7 +383,7 @@ private void compilePatterns(ClassGenerator classGen,
383383
_className = getXSLTC().getHelperClassName();
384384
nodeCounterGen = new NodeCounterGenerator(_className,
385385
ClassNames[_level],
386-
toString(),
386+
getClass().getName(), // Name of this node should be consistent across runs.
387387
ACC_PUBLIC | ACC_SUPER,
388388
null,
389389
classGen.getStylesheet());

src/java.xml/share/classes/com/sun/org/apache/xalan/internal/xsltc/compiler/util/MethodGenerator.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
33
*/
44
/*
55
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -67,6 +67,7 @@
6767
import java.util.ArrayList;
6868
import java.util.Collections;
6969
import java.util.HashMap;
70+
import java.util.LinkedHashMap;
7071
import java.util.Iterator;
7172
import java.util.List;
7273
import java.util.Map;
@@ -75,7 +76,7 @@
7576
/**
7677
* @author Jacek Ambroziak
7778
* @author Santiago Pericas-Geertsen
78-
* @LastModified: July 2019
79+
* @LastModified: Sep 2021
7980
*/
8081
public class MethodGenerator extends MethodGen
8182
implements com.sun.org.apache.xalan.internal.xsltc.compiler.Constants {
@@ -283,7 +284,7 @@ protected class LocalVariableRegistry {
283284
/**
284285
* Maps a name to a {@link LocalVariableGen}
285286
*/
286-
protected Map<String, Object> _nameToLVGMap = new HashMap<>();
287+
protected Map<String, Object> _nameToLVGMap = new LinkedHashMap<>();
287288

288289
/**
289290
* Registers a {@link org.apache.bcel.generic.LocalVariableGen}
@@ -1330,8 +1331,8 @@ public boolean isExternal() {
13301331
// to local variables in the outlined method.
13311332
HashMap<LocalVariableGen, LocalVariableGen> localVarMap = new HashMap<>();
13321333

1333-
HashMap<LocalVariableGen, InstructionHandle> revisedLocalVarStart = new HashMap<>();
1334-
HashMap<LocalVariableGen, InstructionHandle> revisedLocalVarEnd = new HashMap<>();
1334+
HashMap<LocalVariableGen, InstructionHandle> revisedLocalVarStart = new LinkedHashMap<>();
1335+
HashMap<LocalVariableGen, InstructionHandle> revisedLocalVarEnd = new LinkedHashMap<>();
13351336

13361337
// Pass 1: Make copies of all instructions, append them to the new list
13371338
// and associate old instruction references with the new ones, i.e.,

0 commit comments

Comments
 (0)