Abstract
Mnemonics is a Scala library for generating method bodies in JVM bytecode at run time. Mnemonics supports a large subset of the JVM instructions, for which the static typing of the generator guarantees the well-formedness of the generated bytecode.
The library exploits a number of advanced features of Scala’s type system (type inference with bounded polymorphism, implicit parameters, and reflection) to guarantee that the compiler only accepts legal combinations of instructions at compile time. Additional instructions are supported at the price of a check at run time of the generator. In either case, bytecode verification of generated code is guaranteed to succeed.
Similar content being viewed by others
References
Bawden, A.: Quasiquotation in Lisp. In: Danvy, O. (ed.) Proceedings ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation PEPM’99, San Antonio, Texas, USA, pp. 4–12 (1999). BRICS Notes NS-99-1
bcel: Homepage of BCEL. http://jakarta.apache.org/bcel/index.html (2011)
Bruneton, E.: ASM 3.0—A Java Bytecode Engineering Library. http://download.forge.objectweb.org/asm/asm-guide.pdf (2007)
Cardelli, L., Wegner, P.: On understanding types, data abstraction, and polymorphism. Comput. Surv. 17, 471–522 (1985)
Chiba, S., Nishizawa, M.: An easy-to-use toolkit for efficient Java bytecode translators. In: GPCE’03: Proceedings of the 2nd International Conference on Generative Programming and Component Engineering, Erfurt, Germany, pp. 364–376 (2003)
Consel, C., Lawall, J., Marlet, R.: Tempo Specializer—Users’ manual. http://phoenix.labri.fr/software/tempo/doc/tempo-doc-user.html (1998)
Czarnecki, K., O’Donnell, J.T., Striegnitz, J., Taha, W.: DSL implementation in MetaOCaml, template Haskell, and C++. In: [18], pp. 51–72 (2003)
Fluet, M., Pucella, R.: Phantom types and subtyping. J. Funct. Program. 16(6), 751–791 (2006)
Freund, S.N., Mitchell, J.C.: A type system for object initialization in the Java bytecode language. ACM Trans. Program. Lang. Syst. 21(6), 1196–1250 (1999)
Freund, S.N., Mitchell, J.C.: A type system for the Java bytecode language and verifier. J. Autom. Reason. 30(3–4), 271–321 (2003)
Grant, B., Mock, M., Philipose, M., Chambers, C., Eggers, S.J.: DyC: an expressive annotation-directed dynamic compiler for C. Theor. Comput. Sci. 248(1–2), 147–199 (2000)
Jones, M.P.: The functions of Java bytecode. In: Eisenbach, S. (ed.) Formal Underpinnings of Java (1998)
Kfoury, A.J., Wells, J.B.: A direct algorithm for type inference in the rank-2 fragment of the second-order lambda-calculus. In: Proceedings of the 1994 ACM Conference on Lisp and Functional Programming, Orlando, FL, USA, pp. 196–207 (1994)
Kiselyov, O., Shan, C.C.: Lightweight static capabilities. Electron. Notes Theor. Comput. Sci. 174(7), 79–104 (2007)
Kiselyov, O., Lämmel, R., Schupke, K.: Strongly typed heterogeneous collections. In: Haskell ’04: Proceedings of the ACM SIGPLAN workshop on Haskell, Snowbird, Utah, USA, pp. 96–107 (2004)
Launchbury, J., Peyton Jones, S.L.: State in Haskell. Lisp Symb. Comput. 8(4), 293–341 (1995)
Lee, P., Leone, M.: Optimizing ML with run-time code generation. In: Proceedings of the 1996 Conference on Programming Language Design and Implementation, Philadelphia, PA, USA, pp. 137–148 (1996)
Lengauer, C., Batory, D.S., Consel, C., Odersky, M. (eds.): Domain-Specific Program Generation, International Seminar, Dagstuhl, Germany. Lecture Notes in Computer Science, vol. 3016. Springer, Berlin (2004)
Lindholm, T., Yellin, F.: The Java(tm) Virtual Machine Specification, 2nd edn. Addison-Wesley, Reading (1999)
Mainland, G., Morrisett, G., Welsh, M.: Flask: staged functional programming for sensor networks. In: Thiemann, P. (ed.) Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming 2008, Victoria, BC, Canada, pp. 335–346 (2008)
Morris, J.H. Jr.: Protection in programming languages. Commun. ACM 16(1), 15–21 (1973)
Morrisett, J.G., Crary, K., Glew, N., Walker, D.: Stack-based typed assembly language. In: TIC’98: Proceedings of the Second International Workshop on Types in Compilation, Kyoto, Japan. Lecture Notes in Computer Science, vol. 1473, pp. 28–52 (1998)
Nordenberg, J.: MetaScala. http://www.assembla.com/wiki/show/metascala (2008)
Odersky, M., Altherr, P., Cremet, V., Dragos, I., Dubochet, G., Emir, B., McDirmid, S., Micheloud, S., Mihaylov, N., Schinz, M., Spoon, L., Stenman, E., Zenger, M.: An overview of the Scala programming language, 2nd edn. Technical report, EPFL Lausanne (2006)
Odersky, M., Spoon, L., Venners, B.: Programming in Scala: A Comprehensive Step-by-step Guide, 1st edn. Artima Inc, Mountain View (2008)
Odersky, M., Zenger, C., Zenger, M.: Colored local type inference. In: Nielson, H.R. (ed.) Proceedings 28th Annual ACM Symposium on Principles of Programming Languages, London, England, pp. 41–53 (2001)
Oiwa, Y., Masuhara, H., Yonezawa, A.: DynJava: type safe dynamic code generation in Java. In: 3rd JSSST Workshop on Programming and Programming Languages (PPL2001) (2001)
Oury, N., Swierstra, W.: The power of Pi. In: Thiemann, P. (ed.) Proceedings of the 13th ACM SIGPLAN International Conference on Functional Programming, Victoria, BC, Canada, pp. 39–50 (2008)
Poletto, M., Hsieh, W.C., Engler, D.R., Kaashoek, M.F.: ‘C and tcc: a language and compiler for dynamic code generation. ACM Trans. Program. Lang. Syst. 21(2), 324–369 (1999)
Qian, Z.: A formal specification of Java virtual machine instructions for objects, methods and subroutines. In: Formal Syntax and Semantics of Java, pp. 271–312 (1998)
Reynolds, J.C.: Types, abstraction, and parametric polymorphism. In: Mason, R.E.A. (ed.) Information Processing’83, pp. 513–523 (1983)
Rompf, T., Odersky, M.: Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. In: Visser, E., Järvi, J. (eds.) Proceedings of the Ninth International Conference on Generative Programming and Component Engineering, GPCE 2010, Eindhoven, The Netherlands, pp. 127–136 (2010)
Rose, E.: Lightweight bytecode verification. J. Autom. Reason. 31(3–4), 303–334 (2003)
Rudolph, J.: Mnemonics: type-safe bytecode combination in Scala. Diploma thesis, Albert-Ludwigs-Universität Freiburg. http://virtual-void.net/files/mnemonics.zip (2009)
Rudolph, J., Thiemann, P.: Mnemonics: type-safe bytecode generation at run time. In: Gallagher, J.P., Voigtländer, J. (eds.) Proceedings of the 2010 ACM SIGPLAN Workshop on Partial Evaluation and Program Manipulation, PEPM 2010, Madrid, Spain, pp. 15–24 (2010)
Stata, R., Abadi, M.: A type system for Java bytecode subroutines. ACM Trans. Program. Lang. Syst. 21(1), 90–137 (1999)
Taha, W.: A sound reduction semantics for untyped CBN multi-stage computation. In: Lawall, J. (ed.) Proceedings ACM SIGPLAN Workshop on Partial Evaluation and Semantics-Based Program Manipulation PEPM’00, Boston, MA, USA (2000)
Taha, W.: A gentle introduction to multi-stage programming. In: [18], pp. 30–50 (2004)
Taha, W., Nielsen, M.F.: Environment classifiers. In: Morrisett, G. (ed.) Proceedings 30th Annual ACM Symposium on Principles of Programming Languages, New Orleans, LA, USA, pp. 26–37 (2003)
Yelland, P.M.: A compositional account of the Java virtual machine. In: Aiken, A. (ed.) Proceedings 26th Annual ACM Symposium on Principles of Programming Languages, San Antonio, Texas, USA, pp. 57–69 (1999)
Author information
Authors and Affiliations
Corresponding author
Rights and permissions
About this article
Cite this article
Rudolph, J., Thiemann, P. Mnemonics: type-safe bytecode generation at run time. Higher-Order Symb Comput 23, 371–407 (2010). https://doi.org/10.1007/s10990-011-9077-9
Published:
Issue Date:
DOI: https://doi.org/10.1007/s10990-011-9077-9