battlecode-server-2017 icon indicating copy to clipboard operation
battlecode-server-2017 copied to clipboard

Inject strictfp into player code

Open kazimuth opened this issue 9 years ago • 8 comments

Not sure how to do this

kazimuth avatar Jan 07 '17 21:01 kazimuth

Possibly a dumb thought, but since server the class running robotplayer is strictfp, shouldn't all functions (including player code) within it be run with strictfp restrictions as well?

lnductor avatar Jan 07 '17 22:01 lnductor

Server isn't really 'running' RobotPlayer, as the JVM understands it. Server is a loaded class, and RobotPlayer is also a loaded class. (RobotPlayer is loaded by a custom classloader, but that doesn't tell it anything about Server.)

kazimuth avatar Jan 08 '17 01:01 kazimuth

Not exactly a fix (at all), but I just made examplefuncsplayer strictfp because I know a lot of teams use that file as a template.

lnductor avatar Jan 09 '17 17:01 lnductor

Is it possible to use gradle to literally just iterate through all classes in a folder and insert strictfp into each class line?

vontell avatar Jan 09 '17 17:01 vontell

I believe it would be better to accomplish this with the instrumenter somehow.

jbloxham avatar Jan 09 '17 18:01 jbloxham

I can look into this now

lnductor avatar Jan 09 '17 18:01 lnductor

I found a way to force strictfp by setting Opcodes.ACC_STRICT in MethodVisitor. This has an interesting consequence of making testLambdas() fail, as Method test in class instrumented/java/util/function/Predicate has illegal modifiers: 0xC01. I'm assuming this means java.util.function.Predicate is not compatible with strictfp, which means we either have to disallow Predicate or just not have fully-enforced strictfp.

lnductor avatar Jan 09 '17 20:01 lnductor

This is sort of a shot in the dark, but what if you set Opcodes.ACC_STRICT on the classes instead of the methods.

According to JLS §15.4:

If a class, interface, or method, X, is declared strictfp, then X and any class, interface, method, constructor, instance initializer, static initializer, or variable initializer within X is said to be FP-strict.

That would mean that all methods and lambdas which are really inner classes should also be evaluated with fpstrict rules.

Pear0 avatar Jan 17 '17 20:01 Pear0