in ,

Smalltalk with the GraalVM – JVM Advent, Hacker News

Smalltalk with the GraalVM – JVM Advent, Hacker News


Today, we’re going back to the future and do some Smalltalk with the GraalVM.

Introduction

TheJava HotSpot Performance Engineis one of the most sophisticatedprocess virtual machines(VMs) available and used by millions of Java developers every day. If we go back in the early history of HotSpot, not many people may know that HotSpot was initially built by the same team that worked onStrongtalk, a strongly-typed Smalltalk environment as its name suggests. In case you’ve never heard ofSmalltalk: it’s both a programming language and a programming system created by a research group led byAlan Kayat Xerox PARC. Although the community today is quite small compared with those of more mainstream programming languages, Smalltalk systems such asSqueak / Smalltalk, VisualWorks, Pharo , or GemStone / S are still widely used in research and industry to this day.

One of the most interesting developments in current virtual machine research, on the other hand, is theGraalVM project. GraalVM is ahigh-performance virtual machinebased on HotSpot and comes with support for multiple programming languages. At this point, I’m sure you’ve already figured out what this blog post is about: running Smalltalk on the GraalVM!

Motivation

You may be wondering why Smalltalk and GraalVM? For one, it’s, of course, an interesting challenge to bring Smalltalk with all its language features and its programming system to the GraalVM (more on that later).
More importantly, we as aresearch groupare interested in exploring the domain of polyglot programming. Polyglot programming is the practice of writing code in multiple programming languages ​​in the same software project. This gives developers a much broader choice in terms of libraries and frameworks they can re-use.However, we were looking for the right platform that would allow us to experiment with language interoperability and the GraalVM. Instead of having to go through an external API such as theJVM Tool Interface (JVMTI), a Smalltalk programming system would just be yet another programming language on the GraalVM with direct access to all its runtime capabilities.Moreover, Smalltalk comes with a comprehensive set of programming tools with support for exploratory programming and live object inspection that we could adapt to other programming languages.
That’s why we have implemented
GraalSqueak, a Squeak / Smalltalk implementation for the GraalVM.

Implementation Details

Let’s talk a bit about the implementation of GraalSqueak. If you’d like to see some demos first, feel free to skip this section and come back later if you like.

How GraalSqueak Fits into the GraalVM Ecosystem

**********************

GraalVM is built on top of HotSpot technology. Its core component is theGraal compiler, a modern Just-in-time compiler (JIT)

that can be used in conjunction with HotSpot’s C1 and C2 JITs. Furthermore, GraalVM supports multiple languages ​​throughTruffle, its Java -based language implementation framework for building self-specializing AST interpreters. In this framework, the GraalVM team has already implemented various language interpreters, such asGraal. jsfor Javascript and Node.js,FastRfor R,GraalPythonfor Python, and only recently (GraalWasm) for WebAssembly.

GraalSqueak’s Bytecode Interpreter

To support Smalltalk on GraalVM, we therefore needed to implement a Smalltalk VM in Truffle. The first challenge, however, was the fact that Truffle is designed for AST interpreters while the Smalltalk – (specification, as described in the) ******************************** Blue Book

, includes a well -definedbytecodeset similar to Java.Although not well-documented officially, Truffle supports the implementation of bytecode interpreters through a special form of AST representation. This approach is used in GraalVM’sLLVM bitcode interpreterand in GraalSqueak, and explained in detail inthis paper(preprint). If you’re looking for some code, you can find GraalSqueak’s bytecode loophere.

Supporting the Smalltalk Programming System

The Smalltalk programming system, however, needs a lot more than just a bytecode interpreter to work correctly. Smalltalk is mostly written in itself. The compiler, for instance, is written in Smalltalk and so are many language features such as exception handling orreflection. The language also supports some rather uncommon but powerful mechanisms:(allInstances) ****************************************returns a list of all instances for a given class, whilebecome:can be used to swap identities of two objects. Moreover, everything is an object in Smalltalk, including source code. So instead of using files, Smalltalk VMs save snapshots of the entire object memory in a file, so-called (images

**************************, which can then be loaded again later, even on a different platform.

Truffle, on the other hand, does not support most of these features out-of-the-box. Hence, we had to come up with implementation strategies to support all these features on top of Truffle. In the case of (allInstances) ********************************** for example, GraalSqueak walks all objectsjust like a garbage collector. And to load an image file, a Java object is allocated for each Smalltalk objects. To be able to communicate with them from other languages, these objects implement Truffle’s interoperability API. On top of all of this, we also needed to port Various VM pluginssuch as (BitBltand Balloon , which are used by the drawing machinery of Squeak / Smalltalk.

Unfortunately, there isn’t enough time to go into more detail. But if you’d like to learn more about GraalSqueak, its implementation, and limitations, have a look at the GraalSqueak paper( (preprint) ) we presented at (MPLR ‘) ********************************************************************************************************************************************************************************.

GraalSqueak DemoS

So now, it’s time for some demos! In the following screencasts, we run (GraalSqueak 1.0.0-rc6on************************************ (GraalVM) **********************************************************************************************************************************************************************************. 3.0and demonstrate various Smalltalk tools that allow us to interact with different languages.

Workspace, Inspector, and Explorer

****************************************************

GraalSqueak and GraalVM

The first tool is the (Workspace) , which can be used to interactively evaluate code, similar to an interactive shell . For this, it provides so-called (print-Its) (ctrl / cmd p), (inspect-Its) (ctrl / cmd i, explore-Its (******************************** ctrl / cmd e, and (do-Its) ********************************************** ( (ctrl / cmd d) ) to request the execution of code and to display the result. Just like all other GraalVM languages, GraalSqueak provides a Polyglot APIfor evaluating code of other languages ​​and for sharing data and objects between them. What’s interesting here is that you can even interact with something like Javascript’s (Math) module and invoke its (minfunction with arguments from Smalltalk and Python. Additionally, the base language of ourPolyglotWorkspacecan be changed via its context menu. This means the tool can also be used in the same way for all other languages ​​supported by the underlying GraalVM. This demonstrates another advantage of polyglot programming: Language-agnostic tools can provide a much more consistent programming experience and consequently, developers don’t have to learn how to use new tools whenever they learn a new language. Just think about all these different language-specific debuggers for example. Instead, they can keep their preferred debugger and use it for all languages. If you find this idea interesting, have a look at our (paper)preprint) on (LSP

support in Truffle. ****************The next tool shown in the screencast is our (PolyglotInspector) **********************************************. In this case, it’s opened on a Python list and displays both the interface and the contents of the list. The traditional Smalltalk inspector updates frequently to provide more or less live feedback, and so does its polyglot variant. By invoking appendwith a Smalltalk object as the argument, we put the object into the Python list, which is displayed in the inspector shortly after. Lastly, the Inspector can easily be turned into anExplorer, which displays interface and contents in a tree view instead of a list.

Polyglot Notebooks

****************************************************(********************************************

In our (PolyJuS paper) ******* (**************************************** (preprint) ), we have combined multiple workspaces and explorers to build a polyglot, Jupyter-like notebook system. In the video above, we first play around with a Python array and show, how objects can be shared via a special polyglot (bindings) object. Then, we analyze the numbers of contributions for two different programming language conferences per country, always using the best library for the job: Ruby’s (**************************************************************** nokogiri for extracting data from an HTML table, a Python library called(pycountry to clean the data set, R'sggplot2to render a plot, and the tool itself written in Smalltalk. The PolyglotNotebook comes with GraalSqueak. If you're looking for GraalVM-powered Jupyter kernel with similar capabilities, check out our (IPolyglot) kernel.

Java and Smalltalk

****************************************************(********************************************************

Finally, let’s have some fun with Java and Smalltalk! You may have noticed that Java is not listed as one of the supported languages. That’s because there isn’t a Truffle interpreter for Java yet (the GraalVM team is working on itthough). But since Java is the host for all languages ​​running on GraalVM, it is possible to interact with the host Java through a dedicated interface. This, in turn, means we can technically access and interact with all kinds of Java objects including parts of GraalSqueak’s own infrastructure. This allows us to change the title of theJFrame, for example, that GraalSqueak uses for rendering the programming environment. And just because we can, we can callSystem.gc ()to request a garbage collect before quitting GraalSqueak via (System.exit) 42 (******************************************. ***

Conclusions

We hope you enjoyed this dive into Smalltalk, GraalVM, and polyglot programming! If you'd like to give GraalSqueak a try, head over to this GitHub repository

. The README.mdshould cover everything you need to get started ! Please keep in mind, though, that this is an experimental research VM with various limitations at this point. Nonetheless, please nonetheless open issuesif you run into any problems or if you have any questions.

This summer term, we ran our first polyglot programming seminar at Hasso Plattner Institute. So if you’re interested to see what our students have built with GraalSqueak, check out our post on the GraalVM blog. We look forward to using GraalSqueak for both teaching and research on polyglot programming in the next year!

Last but not least, we wish you a wonderful festive season and a happy new year! 🎄🎅🎉

(********************************************************************************


Acknowledgment******************************** (Thanks to) Mani Sarkarfor his feedback on the blog post and to Oracle Labsfor funding our research.

Further Reading

Smalltalk and GraalSqueak (****************************************************************************************

    GraalSqueak: Toward a Smalltalk-based Tooling Platform for Polyglot Programming

( (preprint) ). (************************************************************************************************************* (GraalSqueak: A Fast Smalltalk Bytecode Interpreter Written in an AST Interpreter Framework() ************************************** preprint) . (***************************************************************************************Efficient Implementation of Smalltalk Activation Records in Language Implementation Frameworks( (preprint) ). () ************************************************************************************** (PolyJuS: A Squeak / Smalltalk-based Polyglot Notebook System for the GraalVM( (preprint).

  • (****************************************************************************** Live Multi-language Development and Runtime Environments. (******************************** (Smalltalk –: The Language and Its Implementation( (free version).
    ****************************************************************Back to the future: the story of Squeak, a practical Smalltalk written in itself.Squeak / Smalltalk: (Documentation),******************************************************************************** (Terse Guide to Squeak, Research Papers.

    GraalVM and Truffle) (**************************************************************************************** Implement Your Language

    . ********************************************************************************** (**************************************************************************************************** Truffle Language Implementations. ******************************************************************************** (**************************************************************************************************** One VM to Rule Them All(original GraalVM paper). (************************************************************************************** (Language-independent Development Environment Support for Dynamic Runtimes) (preprint) ). (************************************************************************************************ ()

    ************

    Author: (******************************************************************************************************** Fabio Niephaus

    Fabio Niephaus is a Ph.D. student from the Software Architecture Group, headed by Robert Hirschfeld, at the Hasso Plattner Institute at the University of Potsdam, Germany. He has strong interests in dynamic programming languages, virtual execution environments, and software development tools. As part of his Ph.D. thesis research, he works toward a better polyglot programming experience.

    (************************************************************************************************************

    **************************************************************************************(************************************************************************************************************ (Read More) (****************************************************************************************************

  • What do you think?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    GIPHY App Key not set. Please check settings

    The One-Traffic-Light Town with Some of the Fastest Internet in the U.S., Hacker News

    The One-Traffic-Light Town with Some of the Fastest Internet in the U.S., Hacker News

    Bigg Boss 13: Salman Khan shocks everyone, enters house to console Rashami Desai – Free Press Journal, Freepressjournal.in

    Bigg Boss 13: Salman Khan shocks everyone, enters house to console Rashami Desai – Free Press Journal, Freepressjournal.in