background preloader

JVM-Internals

Facebook Twitter

Java bytecode hacking for fun and profit. With the 2014 season of battlecode starting tomorrow, I figured now would be a good as time as any to finally write up my notes on bytecode hacking.

Java bytecode hacking for fun and profit

If you’re unfamiliar with Battlecode, a good introduction is my previous post (tldr: it’s an intense open-to-all programming competition where teams write AIs for virtual robot armies). You might be wondering what bytecodes have to do with battlecode. Well, one of the most intriguing parts of the battlecode engine is the cost model applied to each team’s AI. In order to hard limit each team’s total computation, yet guarantee equal computation resources to each team, each team is given a bytecode limit, and their code is instrumented and allowed to run only up to that limit before it is halted.

This is pretty counter-intuitive for people who are used to more traditional time-based computational limits. JVM Bytecode Basics To understand how to work around a bytecode limit, we must first understand the JVM’s execution model. Bytecode Counting. JVM Internals. This article explains the internal architecture of the Java Virtual Machine (JVM).

JVM Internals

The following diagram show the key internal components of a typical JVM that conforms to The Java Virtual Machine Specification Java SE 7 Edition. The components shown on this diagram are each explained below in two sections. First section covers the components that are created for each thread and the second section covers the components that are created independently of threads. Thread A thread is a thread of execution in a program. JVM System Threads If you use jconsole or any debugger it is possible to see there are numerous threads running in the background. VM thread This thread waits for operations to appear that require the JVM to reach a safe-point. Learn Linux. Hotspot2. JVM Internals. The Java® Language Specification. Java SE > Java SE Specifications > Java Language Specification The Java® Language Specification Java SE 8 Edition James Gosling Bill Joy Guy Steele Gilad Bracha Alex Buckley Legal Notice.

The Java® Language Specification

Internals of Java Class Loading. By Binildas Christudas 01/26/2005 Class loading is one of the most powerful mechanisms provided by the Java language specification.

Internals of Java Class Loading

Even though the internals of class loading falls under the "advanced topics" heading, all Java programmers should know how the mechanism works and what can be done with it to suit their needs. This can save time that would otherwise have been spent debugging ClassNotFoundException, ClassCastException, etc. This article starts from the basics, such as the difference between code and data, and how they are related to form an instance or object. Then it looks into the mechanism of loading code into the JVM with the help of class loaders, and the main type of class loaders available in Java. Class and Data A class represents the code to be executed, whereas data represents the state associated with that code. Java.lang.Class klass = Myclass.class; Once a class is loaded into a JVM, the same class (I repeat, the same class) will not be loaded again.

Chapter 2. The Structure of the Java Virtual Machine. Chapter 2.

Chapter 2. The Structure of the Java Virtual Machine

Jasmin Home Page. Translation of Lambda Expressions. April 2012 About this document This document outlines the strategy for translating lambda expressions and method references from Java source code into bytecode.

Translation of Lambda Expressions

Lambda expressions for Java are being specified by JSR 335 and implemented in the OpenJDK Lambda Project. An overview of the language feature can be found in State of the Lambda. This document deals with how we arrive at the bytecode that the compiler must generate when it encounters lambda expressions, and how the language runtime participates in evaluating lambda expressions.

Functional interfaces are a central aspect of lambda expressions in Java. Lambda expressions can only appear in places where they will be assigned to a variable whose type is a functional interface. Runnable r = () -> { System.out.println("hello"); }; or Collections.sort(strings, (String a, String b) -> -(a.compareTo(b))); Dependencies and notation Readers should have a working knowledge of the JSR 292 features. Translation strategy Lambda body desugaring Varargs. Understanding JVM Internals. Every developer who uses Java knows that Java bytecode runs in a JRE (Java Runtime Environment).

Understanding JVM Internals

The most important element of the JRE is (JVM), which analyzes and executes Java byte code. Java developers do not need to know how JVM works. So many great applications and libraries have already been developed without developers understanding JVM deeply. However, if you understand JVM, you will understand Java more, and will be able to solve the problems which seem to be so simple but unsolvable. Thus, in this article I will explain how JVM works, its structure, how it executes Java bytecode, the order of execution, examples of common mistakes and their solutions, as well as the new features in Java SE 7 Edition.

Virtual Machine.