A comparative study of bytecode in Scala 2 and 3 and its impact on parsing algorithms
2025 (English)Independent thesis Advanced level (degree of Master (Two Years)), 20 credits / 30 HE credits
Student thesisAlternative title
En komparativ studie av bytekod i Scala 2 och 3 och dess inverkan på parsningsalgoritmer (Swedish)
Abstract [en]
This thesis investigates how the compiler-generated JVM bytecode changes from Scala 2 to Scala 3, and what those changes imply for a bytecode parsing algorithm. Bytecode parsing has many use cases, such as debugging, performance optimization and static code analysis. However, knowledge of the bytecode structure is necessary when designing parsing algorithms. When bytecode changes are introduced, such as with the release of a new compiler version, existing algorithms need to be adapted. As a case study, this thesis uses Modbat, a model-based testing tool that relies on parsing to retrieve debugging information when reporting a failed test case. Modbat is written in Scala 2 and updating such a tool to Scala 3 can be challenging since the structure of Scala 3 bytecode is different. This work thus consists of a comparison of generated bytecode, from Scala 2.11 through Scala 3.4, mainly focusing on the compilation of lambda expressions and function references. In addition, TASTy files, generated by the Scala 3 compiler that contain metadata about the source code, are investigated as an alternative to bytecode for retrieving debugging information. Small example programs, as well as Modbat system models, were compiled for comparison. We catalog identified bytecode differences and discuss their implications for bytecode parsing. We find that the bytecode overall is smaller and simpler, in terms of the number of methods and class files, in Scala 2.12 and later, potentially leading to simpler algorithms. This is mainly due to functional objects being created at runtime, rather than being implemented as individual classes in bytecode. We also find that debugging information, including source files and line numbers of functions, can be reconstructed from TASTy files and could thus serve as an alternative to bytecode for parsing. The results of this thesis is of interest to programmers writing bytecode parsing algorithms for Scala 3, especially those who are updating existing tools from Scala 2 to Scala 3.
Abstract [sv]
Denna avhandling undersöker hur kompilerargenererad JVM-bytekod ändras från Scala 2 till Scala 3, och vad dessa ändringar har för implikationer för algoritmer som parsar bytekod. Bytekodparsning har många användningsfall, som felsökning, prestandaoptimering och statisk kodanalys. Kunskap av byte-kodens struktur är dock nödvänding för design av bytekodparsningsalgoritmer. När ändringar i bytekoden introduceras, exempelvis när en ny version av kompilatorn släpps, måste existerande algoritmer anpassas. Som en fallstudie används Modbat, ett modellbaserat testningsverktyg som använder parsning för att hämta felsökningsinformation för att rapportera misslyckade testfall. Modbat är skrivet i Scala 2, och uppdatering av ett sådant verktyg till Scala 3 kan vara svårt eftersom bytekodstrukturen är annorlunda i Scala 3. Detta arbete innefattar därmed en jämförelse av genererad bytekod, från Scala 2.11 till Scala 3.4, med focus på kompilering av lambdauttryck och funktionreferenser. Dessutom undersöks TASTy-filer, genererade av Scala 3-kompilatorn som innehåller metadata om källkoden, som ett alternativ för bytekod i hämtning av felsökningsinformation. Små exempelprogram och systemmodeller från Modbat kompileras för jämförelse. Vi katalogiserar skillnader i bytekoden och diskuterar deras inverkan på bytekodparsning. Vi finner att bytekoden överlag är mindre och enklare, i termer av antalet metoder och klassfiler, i Scala 2.12 och senare, vilket potentiellt kan leda till enklare algoritmer. Detta är främst på grund av att funktionella object skapas vid körning, i stället för att implementeras som individuella klasser i bytekoden. Vi finner också att felsökningsinformation, inklusive källkodsfiler och radnummer av funktioner, kan rekonstrueras från TASTy-filer och kan därmed fungera som ett alternativ till bytekod för parsning. Dessa resultat är av intresse för programmerare som skriver bytekodparsningsalgoritmer för Scala 3, särskilt de som uppdaterar existerande verktyg från Scala 2 till Scala 3.
Place, publisher, year, edition, pages
2025. , p. 52
Series
TRITA-EECS-EX ; 2025:490
Keywords [en]
Scala, JVM, bytecode, bytecode parsing, TASTy, Modbat
Keywords [sv]
Scala, JVM, bytekod, bytekodparsning, TASTy, Modbat
National Category
Computer and Information Sciences
Identifiers
URN: urn:nbn:se:kth:diva-368131OAI: oai:DiVA.org:kth-368131DiVA, id: diva2:1987416
Supervisors
Examiners
2025-08-112025-08-062025-08-11Bibliographically approved