{"id":1649,"date":"2011-06-07T16:01:28","date_gmt":"2011-06-07T15:01:28","guid":{"rendered":"http:\/\/www.gamlor.info\/wordpress\/?p=1649"},"modified":"2022-12-11T17:15:07","modified_gmt":"2022-12-11T16:15:07","slug":"scala-on-llvm","status":"publish","type":"post","link":"https:\/\/www.gamlor.info\/wordpress\/2011\/06\/scala-on-llvm\/","title":{"rendered":"Scala on LLVM"},"content":{"rendered":"<p>For this semesters \u2018Program Analysis and Transformation\u2019 seminar I took a look on how you could potentially run <a href=\"http:\/\/www.scala-lang.org\/\">Scala<\/a> on the <a href=\"http:\/\/llvm.org\/\">LLVM<\/a>. I created an overview the motivation, implementation possibilities and challenges. The full paper is <a href=\"http:\/\/wiki.ifs.hsr.ch\/SemProgAnTr\/files\/scala-on-llvm-by-roman-stoffel-30-may-2011.PDF\">here<\/a>. This blog post is an short overview that paper.<\/p>\n<h2>Scala on LLVM<\/h2>\n<p>There are three implementation strategies. The first one it to compile Scala with the LLVM tool chain and use it directly. That\u2019s the approach of this project <a href=\"http:\/\/greedy.github.com\/scala\/\">here<\/a>.&nbsp; Another approach is to implement a JVM on top of LLVM, like in the <a href=\"http:\/\/vmkit.llvm.org\/\">VMKit project<\/a>. The third possibility is combine different approaches. For example compile parts of a Scala application with the LLVM tool chain while other parts are compiled to Java byte code. This is mixed approach is interesting to run Scala on specialized Hardware.<\/p>\n<div id=\"attachment_1650\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/run-scala-on-llvm.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1650\" class=\"size-medium wp-image-1650\" title=\"run-scala-on-llvm\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/run-scala-on-llvm-300x195.png\" alt=\"Run Scala on LLVM\" width=\"300\" height=\"195\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/run-scala-on-llvm-300x195.png 300w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/run-scala-on-llvm.png 540w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1650\" class=\"wp-caption-text\">Run Scala on LLVM<\/p><\/div>\n<h2>Challenges<\/h2>\n<p>Scala usually runs on the JVM, which provides much higher level services than LLVM. Therefore when you want to create a 100% Scala implementation you have a lot of stuff to consider. Like garbage collection, threading, the Java memory model, reflection, debugging, dynamic class loading and support for existing Java libraries. Of course you can omit some features if they are not needed for a certain environment.<\/p>\n<div id=\"attachment_1651\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/challanges.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1651\" class=\"size-medium wp-image-1651\" title=\"challanges\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/challanges-300x172.png\" alt=\"Challanges\" width=\"300\" height=\"172\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/challanges-300x172.png 300w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/challanges.png 600w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1651\" class=\"wp-caption-text\">Challenges<\/p><\/div>\n<h2>Interesting Subsets<\/h2>\n<p>Finally the interesting subsets can be the motivation for porting Scala to LLVM.<\/p>\n<h3>Embedded Systems<\/h3>\n<p>One possibility would be to bring Scala to embedded, small systems. Instead of requiring a JVM we could compile Scala down to native code. Of course for such a system it makes sense to remove certain features to keep the implementation small. Stuff like dynamic class loading it probably not needed.<\/p>\n<h3>Scala in Flavors<\/h3>\n<p>One motivation to port Scala could be to create Scala in &#8216;flavors&#8217;. For example that we can parts of a Scala program on specialized hardware, like a GPU. The idea is to isolate certain parts of program, then compile it with the LLVM tool chain for the specialized hardware. The rest is executed normally on a JVM. While the basic idea is simple, in practice it is hard. Nevertheless its a very interesting idea.<\/p>\n<h3>Compiled Scala<\/h3>\n<p>The last thing is to create a full blown, compiled Scala version. However I doubt that it is worth the effort. And you basically can by this already <a href=\"http:\/\/www.excelsior-usa.com\/jet.html\">here<\/a> =).<\/p>\n<div id=\"attachment_1652\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/subsets.png\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-1652\" class=\"size-medium wp-image-1652\" title=\"subsets\" src=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/subsets-300x174.png\" alt=\"Subsets\" width=\"300\" height=\"174\" srcset=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/subsets-300x174.png 300w, https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/subsets.png 587w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-1652\" class=\"wp-caption-text\">Subsets<\/p><\/div>\n<h2>More Stuff<\/h2>\n<p>Again, here\u2019s the <a href=\"http:\/\/wiki.ifs.hsr.ch\/SemProgAnTr\/files\/scala-on-llvm-by-roman-stoffel-30-may-2011.PDF\">full paper<\/a> with a lot more details. Here are the <a href=\"https:\/\/www.gamlor.info\/wordpress\/wp-content\/uploads\/2011\/06\/scala-on-llvm-presentation-outline.pptx\">slides<\/a> of the presentation. And there is more stuff from the seminar from other people: <a href=\"http:\/\/wiki.ifs.hsr.ch\/SemProgAnTr\/files\/LLVM_BasedBugDetection.pdf\">LLVM Based Bug Detection<\/a>, <a href=\"http:\/\/wiki.ifs.hsr.ch\/SemProgAnTr\/files\/Clang_Architecture_-_ChristopherGuntli.pdf\">Architecture of Clang<\/a>, <a href=\"http:\/\/wiki.ifs.hsr.ch\/SemProgAnTr\/files\/yt_template_instantiation_and_concepts_in_clang.pdf\">Template Instantiation and Concepts in CLANG<\/a>, <a href=\"http:\/\/wiki.ifs.hsr.ch\/SemProgAnTr\/files\/LLVM_to_PTX_Backend.pdf\">LLVM to PTX Backend<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>For this semesters \u2018Program Analysis and Transformation\u2019 seminar I took a look on how you could potentially run Scala on the LLVM. I created an overview the motivation, implementation possibilities&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","_links_to":"","_links_to_target":""},"categories":[15,17],"tags":[227,228,226],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/1649"}],"collection":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/comments?post=1649"}],"version-history":[{"count":4,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/1649\/revisions"}],"predecessor-version":[{"id":3940,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/posts\/1649\/revisions\/3940"}],"wp:attachment":[{"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/media?parent=1649"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/categories?post=1649"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gamlor.info\/wordpress\/wp-json\/wp\/v2\/tags?post=1649"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}