Skip to content

Commit 2d8e942

Browse files
Merge remote-tracking branch 'origin/engine' into client
2 parents 6d908a4 + 3e96b6d commit 2d8e942

23 files changed

Lines changed: 176 additions & 112 deletions

build.gradle

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ apply plugin: 'maven-publish'
33

44
import java.nio.file.*
55

6-
sourceCompatibility = 1.8
6+
java {
7+
sourceCompatibility = JavaVersion.VERSION_21
8+
targetCompatibility = JavaVersion.VERSION_21
9+
}
710

8-
if(JavaVersion.current() != JavaVersion.VERSION_1_8) {
9-
throw new GradleException("The engine must be run using the Java 8 JDK")
11+
if(JavaVersion.current() < JavaVersion.VERSION_21) {
12+
throw new GradleException("The engine must be run using >= Java 21 JDK")
1013
}
1114

1215
// Avoid weird configuration-time dependency bugs
@@ -60,6 +63,11 @@ task headless(type: JavaExec, dependsOn: [':engine:build', ':example-bots:build'
6063
classpath = files(serverJar) + project(':example-bots').sourceSets.main.output + configurations.scala
6164
args = ['-c=-']
6265
jvmArgs = [
66+
'--add-opens=java.base/jdk.internal.misc=ALL-UNNAMED',
67+
'--add-opens=java.base/jdk.internal.math=ALL-UNNAMED',
68+
'--add-opens=java.base/jdk.internal.util=ALL-UNNAMED',
69+
'--add-opens=java.base/jdk.internal.access=ALL-UNNAMED',
70+
'--add-opens=java.base/sun.security.action=ALL-UNNAMED',
6371
'-Dbc.server.wait-for-client=' + (project.findProperty('waitForClient') ?: 'false'),
6472
'-Dbc.server.mode=headless',
6573
'-Dbc.server.map-path=maps',
@@ -112,10 +120,10 @@ task release_main(type: Jar, dependsOn: [':engine:build']) {
112120
Files.write(f_version.toPath(), [project.property("release_version")]);
113121
}
114122

115-
archiveBaseName = "battlecode";
123+
archiveBaseName.set("battlecode")
116124
if (project.hasProperty("release_version"))
117-
archiveVersion = project.property("release_version");
118-
destinationDirectory = project.projectDir;
125+
archiveVersion.set(project.property("release_version"))
126+
destinationDirectory.set(project.projectDir)
119127

120128
FileCollection src = files(f_version);
121129
src += zipTree(serverJar);
@@ -133,19 +141,21 @@ task release_docs(type: Jar, dependsOn: [':engine:javadoc']) {
133141
throw new InvalidUserDataException("Must provide property \"release_version\"")
134142
}
135143

136-
archiveBaseName = "battlecode-javadoc"
144+
archiveBaseName.set("battlecode-javadoc")
137145
if (project.hasProperty("release_version"))
138-
archiveVersion = project.property("release_version");
139-
destinationDirectory = project.projectDir;
146+
archiveVersion.set(project.property("release_version"))
147+
destinationDirectory.set(project.projectDir)
148+
archiveClassifier.set('javadoc')
140149

141150
from new File(project(":engine").docsDir, "javadoc")
142151
}
143152

144153
task release_sources(type: Jar, dependsOn: classes) {
145-
archiveBaseName = "battlecode-source"
154+
archiveBaseName.set("battlecode-source")
146155
if (project.hasProperty("release_version"))
147-
archiveVersion = project.property("release_version");
148-
destinationDirectory = project.projectDir;
156+
archiveVersion.set(project.property("release_version"))
157+
destinationDirectory.set(project.projectDir)
158+
archiveClassifier.set('sources')
149159

150160
from project(":engine").sourceSets.main.allSource
151161
}
@@ -158,14 +168,8 @@ publishing {
158168
version project.findProperty('release_version') ?: 'NONSENSE'
159169

160170
artifact release_main
161-
162-
artifact release_docs {
163-
classifier 'javadoc'
164-
}
165-
166-
artifact release_sources {
167-
classifier 'sources'
168-
}
171+
artifact release_docs
172+
artifact release_sources
169173
}
170174

171175
client(MavenPublication) {

engine/build.gradle

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
apply plugin: 'java'
22

3-
sourceCompatibility = 1.8
3+
java {
4+
sourceCompatibility = JavaVersion.VERSION_21
5+
targetCompatibility = JavaVersion.VERSION_21
6+
}
47

58
sourceSets {
69
main {
@@ -38,8 +41,8 @@ dependencies {
3841
[group: 'commons-cli', name: 'commons-cli', version: '1.5.0'],
3942
[group: 'commons-io', name: 'commons-io', version: '2.11.0'],
4043

41-
[group: 'org.ow2.asm', name: 'asm', version: '5.0.4'],
42-
[group: 'org.ow2.asm', name: 'asm-tree', version: '5.0.4'],
44+
[group: 'org.ow2.asm', name: 'asm', version: '9.7.1'],
45+
[group: 'org.ow2.asm', name: 'asm-tree', version: '9.7.1'],
4346

4447
// Flatbuffers
4548
[group: 'com.google.flatbuffers', name: 'flatbuffers-java', version: '23.5.26'],
@@ -53,9 +56,6 @@ dependencies {
5356
// Java Spatial Index, RTree indexing
5457
[group: 'net.sf.jsi', name: 'jsi', version: '1.1.0-SNAPSHOT'],
5558
[group: 'net.sf.trove4j', name: 'trove4j', version: '3.0.3'],
56-
57-
// Javadoc manipulation libraries
58-
files("$System.env.JAVA_HOME" + '/lib/tools.jar')
5959
)
6060

6161
testImplementation(
@@ -73,9 +73,9 @@ jar {
7373

7474
javadoc {
7575
includes = ["**/common/**"]
76-
options.windowTitle = "Battlecode 2022"
76+
options.windowTitle = "Battlecode 2025"
7777
options.classpath = sourceSets.main.compileClasspath as List
78-
options.doclet = "com.sun.tools.doclets.standard.Standard"
78+
options.doclet = "jdk.javadoc.doclet.StandardDoclet"
7979
options.taglets = ["battlecode.doc.CostlyMethodTaglet"]
8080
options.tagletPath = ( sourceSets.main.output.classesDirs as List )+ sourceSets.main.compileClasspath
8181
}

engine/src/main/battlecode/common/GameConstants.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ public class GameConstants {
7676
/** Paint capacity for mopper robots */
7777
public static final int PAINT_CAPACITY_MOPPER = 100;
7878

79-
/** The amount of a paint a paint tower starts with. */
80-
public static final int INITIAL_PAINT_TOWER_PAINT = 500;
81-
8279
/** The amount of money each team starts with. */
8380
public static final int INITIAL_TEAM_MONEY = 1000;
8481

@@ -104,6 +101,12 @@ public class GameConstants {
104101
/** The number of defense towers a player starts with */
105102
public static final int NUMBER_INITIAL_DEFENSE_TOWERS = 0;
106103

104+
/** The amount of a paint a paint tower starts with. */
105+
public static final int INITIAL_PAINT_TOWER_PAINT = 500;
106+
107+
/** The percentage of a robot's paint capacity that is full when first built. */
108+
public static final int INITIAL_ROBOT_PAINT_PERCENTAGE = 50;
109+
107110
/** The width and height of the patterns that robots can draw */
108111
public static final int PATTERN_SIZE = 5;
109112

engine/src/main/battlecode/common/MapLocation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* This class is an immutable representation of two-dimensional coordinates
99
* in the battlecode world.
1010
*/
11-
public final strictfp class MapLocation implements Serializable, Comparable<MapLocation> {
11+
public final class MapLocation implements Serializable, Comparable<MapLocation> {
1212

1313
private static final long serialVersionUID = -8945913587066072824L;
1414
/**

engine/src/main/battlecode/common/RobotController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* controls the newly created robot.
1010
*/
1111
@SuppressWarnings("unused")
12-
public strictfp interface RobotController {
12+
public interface RobotController {
1313

1414
// *********************************
1515
// ****** GLOBAL QUERY METHODS *****

engine/src/main/battlecode/doc/CostlyMethodTaglet.java

Lines changed: 22 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
import battlecode.instrumenter.TeamClassLoaderFactory;
44
import battlecode.instrumenter.bytecode.MethodCostUtil;
5-
import com.sun.javadoc.Tag;
6-
import com.sun.tools.doclets.Taglet;
5+
import com.sun.source.doctree.DocTree;
6+
import javax.lang.model.element.Element;
7+
import javax.lang.model.element.TypeElement;
8+
import javax.lang.model.element.QualifiedNameable;
9+
import jdk.javadoc.doclet.Taglet;
710

11+
import java.util.List;
812
import java.util.Map;
13+
import java.util.Set;
914

1015
/**
1116
* A taglet for the "battlecode.doc.costlymethod" annotation.
@@ -21,45 +26,25 @@ public static void register(Map<String, Taglet> map) {
2126
map.put(TAG_NAME, new CostlyMethodTaglet());
2227
}
2328

24-
public String getName() {
25-
return TAG_NAME;
26-
}
27-
28-
public boolean inConstructor() {
29-
return false;
30-
}
31-
32-
public boolean inField() {
33-
return false;
34-
}
35-
36-
public boolean inMethod() {
37-
return true;
29+
@Override
30+
public Set<Taglet.Location> getAllowedLocations() {
31+
return Set.of(Taglet.Location.METHOD);
3832
}
3933

40-
public boolean inOverview() {
41-
return false;
42-
}
43-
44-
public boolean inPackage() {
45-
return false;
46-
}
47-
48-
public boolean inType() {
49-
return false;
34+
@Override
35+
public String getName() {
36+
return TAG_NAME;
5037
}
5138

39+
@Override
5240
public boolean isInlineTag() {
5341
return false;
5442
}
5543

56-
public String toString(Tag tag) {
57-
final String methodName = tag.holder().name();
58-
final String fileName = tag.holder().position().file().toString();
59-
60-
// Note: this makes an assumption that this method is in the battlecode/ package.
61-
final String className = fileName.substring(fileName.lastIndexOf("battlecode/"),
62-
fileName.length() - 5); // remove .java
44+
public String toString(Element element) {
45+
final String methodName = element.getSimpleName().toString();
46+
final QualifiedNameable enclosingType = (QualifiedNameable) element.getEnclosingElement();
47+
final String className = enclosingType.getQualifiedName().toString().replace('.', '/');
6348

6449
final MethodCostUtil.MethodData data =
6550
MethodCostUtil.getMethodData(className, methodName);
@@ -79,11 +64,11 @@ public String toString(Tag tag) {
7964
"</code></dd>";
8065
}
8166

82-
public String toString(Tag[] tags) {
83-
if (tags.length != 1) {
84-
throw new IllegalArgumentException("Too many @"+TAG_NAME+"tags: "+tags.length);
67+
public String toString(List<? extends DocTree> tags, Element element) {
68+
if (tags.size() != 1) {
69+
throw new IllegalArgumentException("Too many @"+TAG_NAME+"tags: "+tags.size());
8570
}
8671

87-
return toString(tags[0]);
72+
return toString(element);
8873
}
8974
}

engine/src/main/battlecode/instrumenter/bytecode/ClassReferenceUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ private boolean shouldAddInstrumentedPrefix(String className) {
113113
className.startsWith("java/util/jar") ||
114114
className.startsWith("java/util/zip") ||
115115
className.equals("java/util/Iterator") ||
116-
className.equals("java/util/concurrent/TimeUnit"))
116+
className.equals("java/util/concurrent/TimeUnit") ||
117+
// Only instrument part of the jdk internals
118+
(className.startsWith("jdk/internal") && !className.contains("util")))
117119
return false;
118120

119121
if (className.startsWith("java/util/") ||

engine/src/main/battlecode/instrumenter/bytecode/InstrumentingClassVisitor.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public InstrumentingClassVisitor(final ClassVisitor cv,
4343
boolean checkDisallowed,
4444
boolean debugMethodsEnabled,
4545
boolean profilerEnabled) throws InstrumentationException {
46-
super(Opcodes.ASM5, cv);
46+
super(Opcodes.ASM9, cv);
4747
this.loader = loader;
4848
this.silenced = silenced;
4949
this.checkDisallowed = checkDisallowed;
@@ -148,4 +148,17 @@ public void visitInnerClass(String name, String outerName, String innerName, int
148148
);
149149
}
150150

151+
/**
152+
* @inheritDoc
153+
*/
154+
public void visitNestHost(final String nestHost) {
155+
super.visitNestHost(loader.getRefUtil().classReference(nestHost, checkDisallowed));
156+
}
157+
/**
158+
* @inheritDoc
159+
*/
160+
public void visitNestMember(final String nestMember) {
161+
super.visitNestMember(loader.getRefUtil().classReference(nestMember, checkDisallowed));
162+
}
163+
151164
}

engine/src/main/battlecode/instrumenter/bytecode/InstrumentingMethodVisitor.java

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public InstrumentingMethodVisitor(final MethodVisitor mv,
6767
boolean checkDisallowed,
6868
boolean debugMethodsEnabled,
6969
boolean profilerEnabled) {
70-
super(ASM5, access, methodName, methodDesc, signature, exceptions);
70+
super(ASM9, access, methodName, methodDesc, signature, exceptions);
7171
this.methodWriter = mv;
7272

7373
this.loader = loader;
@@ -346,12 +346,13 @@ private void visitInvokeDynamicInsnNode(InvokeDynamicInsnNode n) {
346346
for (int i = 0; i < n.bsmArgs.length; i++) {
347347
final Object arg = n.bsmArgs[i];
348348

349-
if (arg instanceof Type) {
350-
Type t = (Type) arg;
351-
n.bsmArgs[i] = Type.getType(methodDescReference(t.getDescriptor()));
352-
} else if (arg instanceof Handle) {
353-
Handle h = (Handle) arg;
354-
349+
if (arg instanceof Type t) {
350+
n.bsmArgs[i] = switch (t.getSort()){
351+
case Type.METHOD -> Type.getType(methodDescReference(t.getDescriptor()));
352+
case Type.OBJECT, Type.ARRAY -> Type.getType(classDescReference(t.getDescriptor()));
353+
default -> t;
354+
};
355+
} else if (arg instanceof Handle h) {
355356
if (checkDisallowed) {
356357
checkDisallowedMethod(h.getOwner(), h.getName(), h.getDesc());
357358
}
@@ -392,11 +393,18 @@ private void visitInvokeDynamicInsnNode(InvokeDynamicInsnNode n) {
392393
}
393394
}
394395

396+
String desc = switch (Type.getType(h.getDesc()).getSort()) {
397+
case Type.METHOD -> methodDescReference(h.getDesc());
398+
case Type.OBJECT, Type.ARRAY -> classDescReference(h.getDesc());
399+
default -> h.getDesc();
400+
};
401+
395402
n.bsmArgs[i] = new Handle(
396-
h.getTag(),
397-
classReference(h.getOwner()),
398-
h.getName(),
399-
methodDescReference(h.getDesc())
403+
h.getTag(),
404+
classReference(h.getOwner()),
405+
h.getName(),
406+
desc,
407+
h.isInterface()
400408
);
401409
}
402410
}
@@ -417,6 +425,16 @@ private void visitMethodInsnNode(MethodInsnNode n) {
417425
return;
418426
}
419427

428+
if (n.owner.equals("java/util/stream/Stream") && n.name.equals("toList") && n.getOpcode() != INVOKESTATIC) {
429+
bytecodeCtr++;
430+
endOfBasicBlock(n);
431+
n.owner = "battlecode/instrumenter/inject/StreamMethods";
432+
n.desc = "(Ljava/lang/Object;)Ljava/util/List;";
433+
n.itf = false;
434+
n.setOpcode(INVOKESTATIC);
435+
return;
436+
}
437+
420438
if (n.name.equals("toString") && n.desc.equals("()Ljava/lang/String;") && n.getOpcode() != INVOKESTATIC) {
421439
bytecodeCtr++;
422440
endOfBasicBlock(n);

engine/src/main/battlecode/instrumenter/bytecode/InterfaceReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class InterfaceReader extends ClassVisitor {
3030
private String[] interfaces = null;
3131

3232
public InterfaceReader(TeamClassLoaderFactory factory) {
33-
super(Opcodes.ASM5);
33+
super(Opcodes.ASM9);
3434
this.factory = factory;
3535
}
3636

0 commit comments

Comments
 (0)