Today's Topics Java Programs Bytecodes Java Virtual Machine

Total Page:16

File Type:pdf, Size:1020Kb

Today's Topics Java Programs Bytecodes Java Virtual Machine Today’s topics Java programs Parsing Java programs are created as text files using a text editor (like Java Programming emacs) Notes from Tammy Bailey Save to disk with .java file extension HelloWorld.java Reading The file contains characters (stored as bytes) Great Ideas, Chapter 3 & 4 file can be printed, displayed on monitor, or edited file cannot be directly executed (run) by the computer system Java must first translate the program into bytecodes before it can be run CompSci 001 6.1 CompSci 001 6.2 Bytecodes Java Virtual Machine (JVM) Java bytecode Bytecode (class) file will contain exactly the same bytecodes no matter what computer system is used machine instruction for the Java processor Bytecode file is executed by a Java bytecode interpreter Java compiler javac translates the source program into bytecodes processor specific executable program Each type of computer system has its own Java interpreter that Bytecode file has same name as the source program with a can run on that system .class file extension: HelloWorld.class Any computer system can execute Java bytecode programs if it has a Java interpreter Computers with Java interpreters are called Java Virtual Machines a “computer” with a Java processor that can run Java bytecodes HelloWorld.java javac HelloWorld.class source program Java Java bytecodes CompSci 001 compiler 6.3 CompSci 001 6.4 Java applets Data types An applet is a Java bytecode program that runs on a Web Computer memory stores arbitrary bit patterns browser Meaning of a bit pattern depends on its use Most newer Web browsers have Java interpreters Pattern used for a particular string of bits is a data type Web pages on the Internet contain instructions that send Java values are any kind of data a computer can process bytecodes to your computer all values are represented using some data type Web browser runs the Java applet with its built-in interpreter Example: What does the following pattern of 16 bits represent? 0000000001100111 No way to know without more information If data type is short (a Java type) it represents 103 CompSci 001 6.5 CompSci 001 6.6 Java data types Primitive data types Primitive All primitive values belong to one of eight primitive types types of data that are so fundamental ways to represent byte short int long float them are built into Java double char boolean Object Primitive data types use a fixed number of bytes built-in or user-defined four of these types designate different sizes of bounded integers: byte, short, int, long A programmer can not create new primitive data types Any data type you invent will be a type of object Most commonly used types in practice: int, boolean, and double CompSci 001 6.7 CompSci 001 6.8 Java primitive data types Basic operators Primitive Type Description Range Operator Java Description byte 8-bit integer -128 to 127 Assignment = assigns rhs to lhs short 16-bit integer -32768 to 32767 addition, subtraction, Arithmetic +,-,*,/,% multiplication, division, -2147483648 to int 32-bit integer remainder 2147483647 negative, auto increment, auto Unary -,++,-- long 64-bit integer -263 to 263-1 decrement float 32-bit floating point 10-46 to 1038 Equality ==, != equals to, not equals to double 64-bit floating point 10-324 to 10308 less than, less than or equals to, Relational <,<=,>,>= greater than, greater than or equals char Unicode character to boolean Boolean variable false and true Logical &&,||,! AND, OR, NOT CompSci 001 6.9 CompSci 001 6.10 Variable declaration Examples int x, y, z; Declaration type <variable-name>; int sum = 0; Declaration + initialization: float f; type <variable-name> = <value>; double pi = 3.14; Variable names char first = ‘T’, any combination of letters, numbers, and the underscore middle = ‘L’, character last = ‘B’; may not start with number char first = ‘T’; may not be reserved word char middle = ‘L’; • e.g. int, return, if, for, while char last = ‘B’; may not be same as a subroutine name case-sensitive (num and Num are different) CompSci 001 6.11 CompSci 001 6.12 Operator precedence When in doubt, use parentheses Evaluate a + b * c a + b * c = a + (b * c) multiplication first? a + (b * c) because * has higher priority than + addition first? (a + b) * c To perform the + operation first we need to use parentheses Java solves this problem by assigning priorities to operators (a + b) * c (operator precedence) If in any doubt use extra parentheses to ensure the correct Operator priority order of evaluation operators with high priority parentheses are free! are evaluated before (highest to lowest) cause no extra work for the computer operators with low priority only make it easier for you to work out what is happening operators with equal priority 1. ( ) are evaluated left to right 2. * / % 3. + - 4. = CompSci 001 6.13 CompSci 001 6.14 Examples Syntax and semantics Java adheres to traditional order of operations Addition, subtraction: + and –, int and double * and / have higher priority than + and – int x = 3 + 5 * 6; (x = 33) int x = 21+4; (x = 25) int y = (3 + 5) * 6; (y = 48) double y = 14.1-2; (y = 12.1) Parentheses are free, use them liberally Multiplication: *, int and double int z = ((3 + 5) * (6)); (z = 48) int x = 21*4; (x = 84) Equal priority operations are evaluated left-to-right in the double y = 14.1*2.5; (y = 35.25) absence of parentheses Division: /, different for int and double int w = 3 * 4 / 2 * 6; (w = 36) int x = 21/4; (x = 5) int x = 3 * 4 / (2 * 6); (x = 1) double y = 21/4; (y = 5.0) int y = 3 * 4 + 2 * 6; (y = 24) double y = 21/4.0; (y = 5.25) int z = 3 * (4 + 2) * 6; (z = 108) Modulus: %, only for int int x = 21%4; (x = 1) CompSci 001 6.15 CompSci 001 6.16 Automatic type conversion More expressions Mixed type expressions are Example: int g = 12 + 2.5; int n = 1 – 2 * 3 – (4 + 5); converted to higher Convert Fahrenheit to Celsius What is the value of g? compatible types a. 0 What is the value of n? b. 12 If all operands are of type double F=41.0; int then result is type int c. 14 double C=(F-32.0)*(5/9); d. 14.5 If any operand is of type e. error double then result is of type double Question: What is the value of C? Cannot convert to a lower a) 5 type b) 0.0 int x = 8 * (7 – 6 + 5) % (4 + 3 / 2) – 1; Conversion may result in c) 9.0 What is the value of x? loss of precision d) 5.0 a. -1 e) 9 b. 0 c. 2 d. 3 e. none of the above CompSci 001 6.17 CompSci 001 6.18 Syntax errors Logic errors The following Java subroutine computes the inclusive sum The computer will do precisely what you say even though it between two integers. Find all the syntax errors. may not be what you want What is wrong with this code? int sumBetween( x, y ) int sumBetween( int x, int y ) { { int z = x; int z = x; Int sum = 1; int sum = 1; while( z <= y ){ while( z <= y ) sum = sum*z; sum = sum*z; z++ z++; } } CompSci 001 } 6.19 CompSci 001 6.20 Java objects Real-world objects Java is an object-oriented programming language Suppose we want to describe a car in terms of its attributes and functionality use objects to define both the data type and the operations that can be applied to the data Attributes: Objects have attributes and functionality int year; int mileage; String make; String model; attributes describe the state of the object boolean manual_transmission; the functionality of an object is the set of actions the object Methods: can perform void brake() In Java, we define an object’s attributes using variables and its int getMileage() functionality using methods boolean needsGas() void shift(int gear) CompSci 001 6.21 CompSci 001 6.22 Java classes Java String class Java objects are created using classes The String class represents character strings Encapsulation String first = “Tammy”; combining elements to create a new entity String last = “Bailey”; A class encapsulates the variables and methods that define an object Strings can be concatenated (added together) using the concatenation Instantiation operator + the act of creating an object String fullname = first + “ ” + last; objects are called class instances Testing for equality: Java provides many predefined classes first.equals(“Tammy”); /* returns true */ You can also define your own classes first.equals(“Amy”); /* returns false */ CompSci 001 6.23 CompSci 001 6.24.
Recommended publications
  • SJC – Small Java Compiler
    SJC – Small Java Compiler User Manual Stefan Frenz Translation: Jonathan Brase original version: 2011/06/08 latest document update: 2011/08/24 Compiler Version: 182 Java is a registered trademark of Oracle/Sun Table of Contents 1 Quick introduction.............................................................................................................................4 1.1 Windows...........................................................................................................................................4 1.2 Linux.................................................................................................................................................5 1.3 JVM Environment.............................................................................................................................5 1.4 QEmu................................................................................................................................................5 2 Hello World.......................................................................................................................................6 2.1 Source Code......................................................................................................................................6 2.2 Compilation and Emulation...............................................................................................................8 2.3 Details...............................................................................................................................................9
    [Show full text]
  • The LLVM Instruction Set and Compilation Strategy
    The LLVM Instruction Set and Compilation Strategy Chris Lattner Vikram Adve University of Illinois at Urbana-Champaign lattner,vadve ¡ @cs.uiuc.edu Abstract This document introduces the LLVM compiler infrastructure and instruction set, a simple approach that enables sophisticated code transformations at link time, runtime, and in the field. It is a pragmatic approach to compilation, interfering with programmers and tools as little as possible, while still retaining extensive high-level information from source-level compilers for later stages of an application’s lifetime. We describe the LLVM instruction set, the design of the LLVM system, and some of its key components. 1 Introduction Modern programming languages and software practices aim to support more reliable, flexible, and powerful software applications, increase programmer productivity, and provide higher level semantic information to the compiler. Un- fortunately, traditional approaches to compilation either fail to extract sufficient performance from the program (by not using interprocedural analysis or profile information) or interfere with the build process substantially (by requiring build scripts to be modified for either profiling or interprocedural optimization). Furthermore, they do not support optimization either at runtime or after an application has been installed at an end-user’s site, when the most relevant information about actual usage patterns would be available. The LLVM Compilation Strategy is designed to enable effective multi-stage optimization (at compile-time, link-time, runtime, and offline) and more effective profile-driven optimization, and to do so without changes to the traditional build process or programmer intervention. LLVM (Low Level Virtual Machine) is a compilation strategy that uses a low-level virtual instruction set with rich type information as a common code representation for all phases of compilation.
    [Show full text]
  • Scala: a Functional, Object-Oriented Language COEN 171 Darren Atkinson What Is Scala? — Scala Stands for Scalable Language — It Was Created in 2004 by Martin Odersky
    Scala: A Functional, Object-Oriented Language COEN 171 Darren Atkinson What is Scala? Scala stands for Scalable Language It was created in 2004 by Martin Odersky. It was designed to grow with the demands of its users. It was designed to overcome many criticisms of Java. It is compiled to Java bytecode and is interoperable with existing Java classes and libraries. It is more of a high-level language than Java, having higher- order containers and iteration constructs built-in. It encourages a functional programming style, much like ML and Scheme. It also has advanced object-oriented features, much like Java and C++. Using Scala Using Scala is much like using Python or ML, and is not as unwieldy as using Java. The Scala interpreter can be invoked directly from the command line: $ scala Welcome to Scala 2.11.8 scala> println("Hi!") The Scala interpreter can also be given a file on the command line to execute: $ scala foo.scala Scala Syntax Scala has a Java-like syntax with braces. The assignment operator is simply =. Strings are built-in and use + for concatenation. Indexing is done using ( ) rather than [ ]. The first index is index zero. Parameterized types use [ ] rather than < >. A semicolon is inferred at the end of a line. However, since it is functional, everything is an expression and there are no “statements”. Scala Types In Java, the primitive types are not objects and wrapper classes must be used. Integer for int, Boolean for bool, etc. In Scala, everything is an object including the more “primitive” types. The Scala types are Int, Boolean, String, etc.
    [Show full text]
  • Java (Programming Langua a (Programming Language)
    Java (programming language) From Wikipedia, the free encyclopedialopedia "Java language" redirects here. For the natural language from the Indonesian island of Java, see Javanese language. Not to be confused with JavaScript. Java multi-paradigm: object-oriented, structured, imperative, Paradigm(s) functional, generic, reflective, concurrent James Gosling and Designed by Sun Microsystems Developer Oracle Corporation Appeared in 1995[1] Java Standard Edition 8 Update Stable release 5 (1.8.0_5) / April 15, 2014; 2 months ago Static, strong, safe, nominative, Typing discipline manifest Major OpenJDK, many others implementations Dialects Generic Java, Pizza Ada 83, C++, C#,[2] Eiffel,[3] Generic Java, Mesa,[4] Modula- Influenced by 3,[5] Oberon,[6] Objective-C,[7] UCSD Pascal,[8][9] Smalltalk Ada 2005, BeanShell, C#, Clojure, D, ECMAScript, Influenced Groovy, J#, JavaScript, Kotlin, PHP, Python, Scala, Seed7, Vala Implementation C and C++ language OS Cross-platform (multi-platform) GNU General Public License, License Java CommuniCommunity Process Filename .java , .class, .jar extension(s) Website For Java Developers Java Programming at Wikibooks Java is a computer programming language that is concurrent, class-based, object-oriented, and specifically designed to have as few impimplementation dependencies as possible.ble. It is intended to let application developers "write once, run ananywhere" (WORA), meaning that code that runs on one platform does not need to be recompiled to rurun on another. Java applications ns are typically compiled to bytecode (class file) that can run on anany Java virtual machine (JVM)) regardless of computer architecture. Java is, as of 2014, one of tthe most popular programming ng languages in use, particularly for client-server web applications, witwith a reported 9 million developers.[10][11] Java was originallyy developed by James Gosling at Sun Microsystems (which has since merged into Oracle Corporation) and released in 1995 as a core component of Sun Microsystems'Micros Java platform.
    [Show full text]
  • The Java® Language Specification Java SE 8 Edition
    The Java® Language Specification Java SE 8 Edition James Gosling Bill Joy Guy Steele Gilad Bracha Alex Buckley 2015-02-13 Specification: JSR-337 Java® SE 8 Release Contents ("Specification") Version: 8 Status: Maintenance Release Release: March 2015 Copyright © 1997, 2015, Oracle America, Inc. and/or its affiliates. 500 Oracle Parkway, Redwood City, California 94065, U.S.A. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners. The Specification provided herein is provided to you only under the Limited License Grant included herein as Appendix A. Please see Appendix A, Limited License Grant. To Maurizio, with deepest thanks. Table of Contents Preface to the Java SE 8 Edition xix 1 Introduction 1 1.1 Organization of the Specification 2 1.2 Example Programs 6 1.3 Notation 6 1.4 Relationship to Predefined Classes and Interfaces 7 1.5 Feedback 7 1.6 References 7 2 Grammars 9 2.1 Context-Free Grammars 9 2.2 The Lexical Grammar 9 2.3 The Syntactic Grammar 10 2.4 Grammar Notation 10 3 Lexical Structure 15 3.1 Unicode 15 3.2 Lexical Translations 16 3.3 Unicode Escapes 17 3.4 Line Terminators 19 3.5 Input Elements and Tokens 19 3.6 White Space 20 3.7 Comments 21 3.8 Identifiers 22 3.9 Keywords 24 3.10 Literals 24 3.10.1 Integer Literals 25 3.10.2 Floating-Point Literals 31 3.10.3 Boolean Literals 34 3.10.4 Character Literals 34 3.10.5 String Literals 35 3.10.6 Escape Sequences for Character and String Literals 37 3.10.7 The Null Literal 38 3.11 Separators
    [Show full text]
  • Toward IFVM Virtual Machine: a Model Driven IFML Interpretation
    Toward IFVM Virtual Machine: A Model Driven IFML Interpretation Sara Gotti and Samir Mbarki MISC Laboratory, Faculty of Sciences, Ibn Tofail University, BP 133, Kenitra, Morocco Keywords: Interaction Flow Modelling Language IFML, Model Execution, Unified Modeling Language (UML), IFML Execution, Model Driven Architecture MDA, Bytecode, Virtual Machine, Model Interpretation, Model Compilation, Platform Independent Model PIM, User Interfaces, Front End. Abstract: UML is the first international modeling language standardized since 1997. It aims at providing a standard way to visualize the design of a system, but it can't model the complex design of user interfaces and interactions. However, according to MDA approach, it is necessary to apply the concept of abstract models to user interfaces too. IFML is the OMG adopted (in March 2013) standard Interaction Flow Modeling Language designed for abstractly expressing the content, user interaction and control behaviour of the software applications front-end. IFML is a platform independent language, it has been designed with an executable semantic and it can be mapped easily into executable applications for various platforms and devices. In this article we present an approach to execute the IFML. We introduce a IFVM virtual machine which translate the IFML models into bytecode that will be interpreted by the java virtual machine. 1 INTRODUCTION a fundamental standard fUML (OMG, 2011), which is a subset of UML that contains the most relevant The software development has been affected by the part of class diagrams for modeling the data apparition of the MDA (OMG, 2015) approach. The structure and activity diagrams to specify system trend of the 21st century (BRAMBILLA et al., behavior; it contains all UML elements that are 2014) which has allowed developers to build their helpful for the execution of the models.
    [Show full text]
  • Superoptimization of Webassembly Bytecode
    Superoptimization of WebAssembly Bytecode Javier Cabrera Arteaga Shrinish Donde Jian Gu Orestis Floros [email protected] [email protected] [email protected] [email protected] Lucas Satabin Benoit Baudry Martin Monperrus [email protected] [email protected] [email protected] ABSTRACT 2 BACKGROUND Motivated by the fast adoption of WebAssembly, we propose the 2.1 WebAssembly first functional pipeline to support the superoptimization of Web- WebAssembly is a binary instruction format for a stack-based vir- Assembly bytecode. Our pipeline works over LLVM and Souper. tual machine [17]. As described in the WebAssembly Core Specifica- We evaluate our superoptimization pipeline with 12 programs from tion [7], WebAssembly is a portable, low-level code format designed the Rosetta code project. Our pipeline improves the code section for efficient execution and compact representation. WebAssembly size of 8 out of 12 programs. We discuss the challenges faced in has been first announced publicly in 2015. Since 2017, it has been superoptimization of WebAssembly with two case studies. implemented by four major web browsers (Chrome, Edge, Firefox, and Safari). A paper by Haas et al. [11] formalizes the language and 1 INTRODUCTION its type system, and explains the design rationale. The main goal of WebAssembly is to enable high performance After HTML, CSS, and JavaScript, WebAssembly (WASM) has be- applications on the web. WebAssembly can run as a standalone VM come the fourth standard language for web development [7]. This or in other environments such as Arduino [10]. It is independent new language has been designed to be fast, platform-independent, of any specific hardware or languages and can be compiled for and experiments have shown that WebAssembly can have an over- modern architectures or devices, from a wide variety of high-level head as low as 10% compared to native code [11].
    [Show full text]
  • Building Useful Program Analysis Tools Using an Extensible Java Compiler
    Building Useful Program Analysis Tools Using an Extensible Java Compiler Edward Aftandilian, Raluca Sauciuc Siddharth Priya, Sundaresan Krishnan Google, Inc. Google, Inc. Mountain View, CA, USA Hyderabad, India feaftan, [email protected] fsiddharth, [email protected] Abstract—Large software companies need customized tools a specific task, but they fail for several reasons. First, ad- to manage their source code. These tools are often built in hoc program analysis tools are often brittle and break on an ad-hoc fashion, using brittle technologies such as regular uncommon-but-valid code patterns. Second, simple ad-hoc expressions and home-grown parsers. Changes in the language cause the tools to break. More importantly, these ad-hoc tools tools don’t provide sufficient information to perform many often do not support uncommon-but-valid code code patterns. non-trivial analyses, including refactorings. Type and symbol We report our experiences building source-code analysis information is especially useful, but amounts to writing a tools at Google on top of a third-party, open-source, extensible type-checker. Finally, more sophisticated program analysis compiler. We describe three tools in use on our Java codebase. tools are expensive to create and maintain, especially as the The first, Strict Java Dependencies, enforces our dependency target language evolves. policy in order to reduce JAR file sizes and testing load. The second, error-prone, adds new error checks to the compilation In this paper, we present our experience building special- process and automates repair of those errors at a whole- purpose tools on top of the the piece of software in our codebase scale.
    [Show full text]
  • SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs
    SUBJECT-COMPUTER CLASS-12 CHAPTER 9 – Compiling and Running Java Programs Introduction to Java programming JAVA was developed by Sun Microsystems Inc in 1991, later acquired by Oracle Corporation. It was developed by James Gosling and Patrick Naughton. It is a simple programming language. Writing, compiling and debugging a program is easy in java. It helps to create modular programs and reusable code. Bytecode javac compiler of JDK compiles the java source code into bytecode so that it can be executed by JVM. The bytecode is saved in a .class file by compiler. Java Virtual Machine (JVM) This is generally referred as JVM. Before, we discuss about JVM lets see the phases of program execution. Phases are as follows: we write the program, then we compile the program and at last we run the program. 1) Writing of the program is of course done by java programmer. 2) Compilation of program is done by javac compiler, javac is the primary java compiler included in java development kit (JDK). It takes java program as input and generates java bytecode as output. 3) In third phase, JVM executes the bytecode generated by compiler. This is called program run phase. So, now that we understood that the primary function of JVM is to execute the bytecode produced by compiler. Characteristics of Java Simple Java is very easy to learn, and its syntax is simple, clean and easy to understand. Multi-threaded Multithreading capabilities come built right into the Java language. This means it is possible to build highly interactive and responsive apps with a number of concurrent threads of activity.
    [Show full text]
  • Coqjvm: an Executable Specification of the Java Virtual Machine Using
    CoqJVM: An Executable Specification of the Java Virtual Machine using Dependent Types Robert Atkey LFCS, School of Informatics, University of Edinburgh Mayfield Rd, Edinburgh EH9 3JZ, UK [email protected] Abstract. We describe an executable specification of the Java Virtual Machine (JVM) within the Coq proof assistant. The principal features of the development are that it is executable, meaning that it can be tested against a real JVM to gain confidence in the correctness of the specification; and that it has been written with heavy use of dependent types, this is both to structure the model in a useful way, and to constrain the model to prevent spurious partiality. We describe the structure of the formalisation and the way in which we have used dependent types. 1 Introduction Large scale formalisations of programming languages and systems in mechanised theorem provers have recently become popular [4–6, 9]. In this paper, we describe a formalisation of the Java virtual machine (JVM) [8] in the Coq proof assistant [11]. The principal features of this formalisation are that it is executable, meaning that a purely functional JVM can be extracted from the Coq development and – with some O’Caml glue code – executed on real Java bytecode output from the Java compiler; and that it is structured using dependent types. The motivation for this development is to act as a basis for certified consumer- side Proof-Carrying Code (PCC) [12]. We aim to prove the soundness of program logics and correctness of proof checkers against the model, and extract the proof checkers to produce certified stand-alone tools.
    [Show full text]
  • Program Dynamic Analysis Overview
    4/14/16 Program Dynamic Analysis Overview • Dynamic Analysis • JVM & Java Bytecode [2] • A Java bytecode engineering library: ASM [1] 2 1 4/14/16 What is dynamic analysis? [3] • The investigation of the properties of a running software system over one or more executions 3 Has anyone done dynamic analysis? [3] • Loggers • Debuggers • Profilers • … 4 2 4/14/16 Why dynamic analysis? [3] • Gap between run-time structure and code structure in OO programs Trying to understand one [structure] from the other is like trying to understand the dynamism of living ecosystems from the static taxonomy of plants and animals, and vice-versa. -- Erich Gamma et al., Design Patterns 5 Why dynamic analysis? • Collect runtime execution information – Resource usage, execution profiles • Program comprehension – Find bugs in applications, identify hotspots • Program transformation – Optimize or obfuscate programs – Insert debugging or monitoring code – Modify program behaviors on the fly 6 3 4/14/16 How to do dynamic analysis? • Instrumentation – Modify code or runtime to monitor specific components in a system and collect data – Instrumentation approaches • Source code modification • Byte code modification • VM modification • Data analysis 7 A Running Example • Method call instrumentation – Given a program’s source code, how do you modify the code to record which method is called by main() in what order? public class Test { public static void main(String[] args) { if (args.length == 0) return; if (args.length % 2 == 0) printEven(); else printOdd(); } public
    [Show full text]
  • Nashorn Architecture and Performance Improvements in the Upcoming JDK 8U40 Release
    Oracle Blogs Home Products & Services Downloads Support Partners Communities About Login Oracle Blog Nashorn JavaScript for the JVM. Nashorn architecture and performance improvements in the upcoming JDK 8u40 release By lagergren on Dec 12, 2014 Hello everyone! We've been bad att blogging here for a while. Apologizes for that. I thought it would be prudent to talk a little bit about OpenJDK 8u40 which is now code frozen, and what enhancements we have made for Nashorn. 8u40 includes a total rewrite of the Nashorn code generator, which now contains the optimistic type system. JavaScript, or any dynamic language for that matter, doesn't have enough statically available type information to provide performant code, just by doing compile time analysis. That's why we have designed the new type system to get around this performance bottleneck. While Java bytecode, which is the output of the Nashorn JIT, is strongly typed and JavaScript isn't, there are problems translating the AST to optimal bytecode. Attila Szegedi, Hannes Wallnöfer and myself have spent significant time researching and implementing this the last year. Background: Conservatively, when implementing a JavaScript runtime in Java, anything known to be a number can be represented in Java as a double, and everything else can be represented as an Object. This includes numbers, ints, longs and other primitive types that aren't statically provable. Needless to say, this approach leads to a lot of internal boxing, which is quite a bottleneck for dynamic language execution speed on the JVM. The JVM is very good at optimizing Java-like bytecode, and this is not Java-like bytecode.
    [Show full text]