The technique of superoptimization attempts to ensure true optimality of a code (according to predefined criteria) through an exhaustive search of all potentially viable programs. Implementations have demonstrated that superoptimizers are capable of finding shorter programs than those hand optimized for size by experts or produced by conventional compilers. Superoptimizers have been developed for many machine architectures and used for diverse purposes including automating peephole optimization and binary translation of instruction sets. The output of superoptimizers is frequently surprising to human experts and often takes advantage of side effects or obscure characteristics of the targeted hardware. Virtual machines (VMs) are increasingly popular in implementations of programming languages, because they can provide a common platform across heterogeneous hardware architectures. This paper examines whether superoptimization could be a viable technique for VMs. A superoptimizer for the Java VM (JVM) has been developed and used to generate demonstrably size-optimized versions of some simple mathematical functions, implemented in a Java bytecode. We have shown that these versions are shorter than both implementations shipped with the Java software development kit and those generated by the Java compiler. We also have some useful observations concerning techniques to allow larger programs to be optimized in a reasonable time by this approach. Copyright © 2013 John Wiley & Sons, Ltd.