In this presentation, Doug Hawkins will discuss how the Dalvik VM is different from traditional Java VMs and the motivations behind those differences. Along the way, you'll learn about Android's service architecture, Dalvik's byte code format, and the surprising details of how Android installs, launches, and executes applications.
Demian Neidetcher's presentation to the Denver Open Source Users Group on the Android mobile phone platform. Full details and source code available at http://neidetcher.com/android.html
Learning, Analyzing and Protecting Android with TOMOYO Linux (JLS2009)Toshiharu Harada, Ph.D
TOMOYO Linux is a MAC (Mandatory Access Control) implementation which gives support to protect Linux systems as well as to learn, understand and analyze system behavior. Being lightweight, it results suitable for embedded systems too. This tutorial aims to show in a practical way how to make the best use of TOMOYO Linux potentials in order to study and protect embedded Linux systems, taking Android as a specific study case. Though Android is amazingly expanding its target to various kinds of devices, it was designed mainly for mobile phones. Then, unlike other embedded operating systems, it presents some peculiar characteristics which require a particular attention to apply MAC effectively. The session is directed to those who want to learn how to use TOMOYO Linux, to managers or developers interested in security concerning embedded Linux and Android, and even to anyone just wishing to take a closer glance at Android internals.
Presentation at Android Builders Summit 2012.
Based on the experience of working with ODM companies and SoC vendors, this session would discuss how to figure out the performance hotspot of certain Android devices and then improve in various areas including graphics and boot time. This session consists of the detailed components which seem to be independent from each other in traditional view. However, the situation changes a lot in Android system view since everything is coupled in a mass. Three frequently mentioned items in Android engineering are selected as the entry points: 2D/3D graphics, runtime, and boot time. Audience: Developers who work on Android system integration and platform enablement.
Linaro's mission is to make it easier and quicker for ARM partners to deploy the latest technology into optimized Linux based products. This presentation covers the basic work from Linaro Android platform team.
In this presentation, the unaware or indirect applications of essential computer science concepts are dicussed as showcase. Jim Huang presented in Department of Computer Science and Engineering, National Taiwan University.
Demian Neidetcher's presentation to the Denver Open Source Users Group on the Android mobile phone platform. Full details and source code available at http://neidetcher.com/android.html
Learning, Analyzing and Protecting Android with TOMOYO Linux (JLS2009)Toshiharu Harada, Ph.D
TOMOYO Linux is a MAC (Mandatory Access Control) implementation which gives support to protect Linux systems as well as to learn, understand and analyze system behavior. Being lightweight, it results suitable for embedded systems too. This tutorial aims to show in a practical way how to make the best use of TOMOYO Linux potentials in order to study and protect embedded Linux systems, taking Android as a specific study case. Though Android is amazingly expanding its target to various kinds of devices, it was designed mainly for mobile phones. Then, unlike other embedded operating systems, it presents some peculiar characteristics which require a particular attention to apply MAC effectively. The session is directed to those who want to learn how to use TOMOYO Linux, to managers or developers interested in security concerning embedded Linux and Android, and even to anyone just wishing to take a closer glance at Android internals.
Presentation at Android Builders Summit 2012.
Based on the experience of working with ODM companies and SoC vendors, this session would discuss how to figure out the performance hotspot of certain Android devices and then improve in various areas including graphics and boot time. This session consists of the detailed components which seem to be independent from each other in traditional view. However, the situation changes a lot in Android system view since everything is coupled in a mass. Three frequently mentioned items in Android engineering are selected as the entry points: 2D/3D graphics, runtime, and boot time. Audience: Developers who work on Android system integration and platform enablement.
Linaro's mission is to make it easier and quicker for ARM partners to deploy the latest technology into optimized Linux based products. This presentation covers the basic work from Linaro Android platform team.
In this presentation, the unaware or indirect applications of essential computer science concepts are dicussed as showcase. Jim Huang presented in Department of Computer Science and Engineering, National Taiwan University.
(Presentation at HITcon 2011) This talk introduces how to do Android application reverse engineering by real example. And, it covers the advanced topics like optimized DEX and JNI.
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
SurfaceFlinger is a vital system service in Android system, responsible for the composting all the application and system layer and displaying them. In this slide,we looked in detail how surfaceFlinger was designed from Design Pattern's perspective.
How to implement a simple dalvik virtual machineChun-Yu Wang
This slide is an introduction to Android Dalvik Virtual Machine on a short course.
We use two hand-made JVM and DVM which called Simple JVM and Simple DVM respectively, to tell student how they work. A Foo Class was provided as a target for verifying the execution results of those VM. We hope it will help student to understand JVM and DVM quickly.
With growth in app market it is essential to guard our android apps against possible threats, in this presentation we will walk through various tools and techniques which some one can use to reverse engineer an android app, we will see how some one can get access to APP DB, CODE, API, PREFERENCES.
We will also see different tools and techniques to guard our app against possible threats from code obfuscation with tools like dexgaurd to newer methods like verification of api calls using google play services.
This session was taken in Barcamp 13 bangalore http://barcampbangalore.org/bcb/bcb13/reverse-engineering-an-android-app-securing-your-android-apps-against-attacks
and bangalore android user group meetup Jan meetup http://www.meetup.com/blrdroid/events/100360682/
Presentation at FreedomHEC 2012 Conference. 0xlab extends DMTCP (Distributed Multi-Threaded CheckPointing) to enable Android checkpointing, which leads to resume to stored state for faster Android boot time and make better product field trial experience.
안드로이드에서 비디오 재생하는 법, MediaPlayer와 VideoView를 정리했습니다.
예제 소스: https://github.com/luvgaram/android_GDG_examples
GDG Korea 2015 11월 정기모임에서 발표한 자료입니다.
NHN NEXT 모바일 전공 임은주
EclipseCon 2011: Deciphering the CDT debugger alphabet soupBruce Griffith
CDT: So you want me to use which debugger ... ?
Deciphering the CDT debugger alphabet soup.
Bruce Griffith
John Cortell (Freescale Semiconductor)
As the developer of an IDE based on CDT, you can choose to support:
The GNU debugger (gdb)
The Eclipse Debugger for C/C++ (EDC)
Debug Services Framework (DSF)
Target Communication Framework (TCF) agents
How do you decide which ones are right for your application?
This talk will present a guide describing how the current choices for remote debugging work together (or don’t) and a consumer’s view of the advantages of some of the possible combinations.
Droidcon Greece '15 - Reverse Engineering in Android: Countermeasures and ToolsDario Incalza
Reverse Engineering (RE) is the art of taking an application apart and try to understand the internal mechanisms.
There’s a positive side and a negative side to this approach. The positive side is the fact that RE gives us a means to research and understand malware.
The negative side is that distributed binaries can be torn apart to look at intellectual property or to inject it with malicious code.
The talk will guide you through the Android app build process and learn some countermeasures to make it harder for hackers to reverse engineer your Android code. Further more the talk will cover opensource tools that you can use to reverse engineer Android applications to inspect it for malware.
Overview of Android NDK (Native Development Toolkit).
Android application development is primarily done with the Android SDK.
Apps are written in Java thus benefitting from the high-level constructs
of the managed environment as well as the wealth of functionality provided
by the Android application platform.
However, sometimes it is necessary to implement certain functionality natively
in C++, e.g. when access to hardware is required or 3rd party stacks have to
be included that are only available as C++ code.
The NDK is a lightweight development toolkit for writing native applications
and libraries that can interwork with Java application code.
The new runtime which Google is started implementing as developers view to implement or not which has advantages over the previous Dalvik runtime and more...
(Presentation at HITcon 2011) This talk introduces how to do Android application reverse engineering by real example. And, it covers the advanced topics like optimized DEX and JNI.
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveBin Chen
SurfaceFlinger is a vital system service in Android system, responsible for the composting all the application and system layer and displaying them. In this slide,we looked in detail how surfaceFlinger was designed from Design Pattern's perspective.
How to implement a simple dalvik virtual machineChun-Yu Wang
This slide is an introduction to Android Dalvik Virtual Machine on a short course.
We use two hand-made JVM and DVM which called Simple JVM and Simple DVM respectively, to tell student how they work. A Foo Class was provided as a target for verifying the execution results of those VM. We hope it will help student to understand JVM and DVM quickly.
With growth in app market it is essential to guard our android apps against possible threats, in this presentation we will walk through various tools and techniques which some one can use to reverse engineer an android app, we will see how some one can get access to APP DB, CODE, API, PREFERENCES.
We will also see different tools and techniques to guard our app against possible threats from code obfuscation with tools like dexgaurd to newer methods like verification of api calls using google play services.
This session was taken in Barcamp 13 bangalore http://barcampbangalore.org/bcb/bcb13/reverse-engineering-an-android-app-securing-your-android-apps-against-attacks
and bangalore android user group meetup Jan meetup http://www.meetup.com/blrdroid/events/100360682/
Presentation at FreedomHEC 2012 Conference. 0xlab extends DMTCP (Distributed Multi-Threaded CheckPointing) to enable Android checkpointing, which leads to resume to stored state for faster Android boot time and make better product field trial experience.
안드로이드에서 비디오 재생하는 법, MediaPlayer와 VideoView를 정리했습니다.
예제 소스: https://github.com/luvgaram/android_GDG_examples
GDG Korea 2015 11월 정기모임에서 발표한 자료입니다.
NHN NEXT 모바일 전공 임은주
EclipseCon 2011: Deciphering the CDT debugger alphabet soupBruce Griffith
CDT: So you want me to use which debugger ... ?
Deciphering the CDT debugger alphabet soup.
Bruce Griffith
John Cortell (Freescale Semiconductor)
As the developer of an IDE based on CDT, you can choose to support:
The GNU debugger (gdb)
The Eclipse Debugger for C/C++ (EDC)
Debug Services Framework (DSF)
Target Communication Framework (TCF) agents
How do you decide which ones are right for your application?
This talk will present a guide describing how the current choices for remote debugging work together (or don’t) and a consumer’s view of the advantages of some of the possible combinations.
Droidcon Greece '15 - Reverse Engineering in Android: Countermeasures and ToolsDario Incalza
Reverse Engineering (RE) is the art of taking an application apart and try to understand the internal mechanisms.
There’s a positive side and a negative side to this approach. The positive side is the fact that RE gives us a means to research and understand malware.
The negative side is that distributed binaries can be torn apart to look at intellectual property or to inject it with malicious code.
The talk will guide you through the Android app build process and learn some countermeasures to make it harder for hackers to reverse engineer your Android code. Further more the talk will cover opensource tools that you can use to reverse engineer Android applications to inspect it for malware.
Overview of Android NDK (Native Development Toolkit).
Android application development is primarily done with the Android SDK.
Apps are written in Java thus benefitting from the high-level constructs
of the managed environment as well as the wealth of functionality provided
by the Android application platform.
However, sometimes it is necessary to implement certain functionality natively
in C++, e.g. when access to hardware is required or 3rd party stacks have to
be included that are only available as C++ code.
The NDK is a lightweight development toolkit for writing native applications
and libraries that can interwork with Java application code.
The new runtime which Google is started implementing as developers view to implement or not which has advantages over the previous Dalvik runtime and more...
This set of slides introduces the basics of the Android development framework and mobile development in general. First, a brief overview on the history of mobile development is introduced. Then, the architecture of the Android platform is discussed, commenting on the role and functionalities of each architectural layer.
Objective of this article is to share internal architecture details of Java Virtual Machine. Focuses on:
- How many component does JVM has?
- How these component are integrated?
- How processing takes place at run time for classes?
Two hour lecture I gave at the Jyväskylä Summer School. The purpose of the talk is to give a quick non-technical overview of concepts and methodologies in data science. Topics include a wide overview of both pattern mining and machine learning.
See also Part 2 of the lecture: Industrial Data Science. You can find it in my profile (click the face)
Introduction to Data Science and AnalyticsSrinath Perera
This webinar serves as an introduction to WSO2 Summer School. It will discuss how to build a pipeline for your organization and for each use case, and the technology and tooling choices that need to be made for the same.
This session will explore analytics under four themes:
Hindsight (what happened)
Oversight (what is happening)
Insight (why is it happening)
Foresight (what will happen)
Recording http://t.co/WcMFEAJHok
So you've reversed you're first Android APK; now what? Java pseduocode is nice, but how do we modify the app? This is a crash course in reading and understanding Davlik opcodes. It will go through some basics then we will jump into a couple case studies to demonstrate some of the concepts. This talk should help testers who are interested in or do Android application assessments to better understand how to mess with the underlying code.
While Android programming is based on Java, there are some important philosophical differences and Android-specific constructs to consider. Android for Java Developers is an action-packed, hands-on presentation that takes you through the anatomy of an Android application. The sample application includes most major Android building blocks (Activities, Intents, Services, Broadcast Receivers, Content Providers) to illustrate the philosophy of Android application development. It assumes basic Java knowledge.
Especially in small companies, you're often expected to be the end-to-end developer and handle everything from the database to the user interface. This was easy enough in the old days when the UI was little more than a table-based-layout with some sliced graphics. But now with the latest technologies, the front end is becoming just as complex as the back end. In order to get the job done you need to rely more and more upon an ever growing, endless mountain of JavaScript libraries, plugins and boilerplates. Or maybe... you just need a front end developer.
for the presentation iMoot 2012
This software was changed its name to 'Acfvideo' standing on Amazon Cloud Frond .
The source is here .
https://github.com/matsuzakit/moodle-activity_acfvideo
English presentation is here .
https://www.youtube.com/watch?v=3XVFVL6LSDo
Docker Deep Dive Understanding Docker Engine Docker for DevOpsMehwishHayat3
Up and running with docker, How docker engine works, Why use Docker as a web developer, How Docker help us achieving consistent environment for developing web app, How Docker swarm help us a DevOps, What are namespace and control groups, How images are different from container, What is content addressable storage, what is Fat mainfest and image manifest, Dot cloud and Docker.
Flex For Java Architects Ledroff Breizh Jug V Blog CcFrançois Le Droff
I had the chance to present at the BreizhJUG (a Breton Java user group) a session named "Flex for Java Deveoppers".
A crowd of almost 100 happy Java developers and architects was willing to know more about Flex.
I had an an hour and half to cover :
*
a basic presentation of the flash and AIR platforms,
*
cool UX flash/flex/AIR demos
*
the latest great features of flash 10
*
and flex, and its ecosystem from a Java developer perspective (mvn framework, testing libraries, building and quality tools, blazeds, lcds)
I ended up the session presenting fna maven archetypes
Similar to Inside Android's Dalvik VM - NEJUG Nov 2011 (20)
JVM Mechanics: Understanding the JIT's TricksDoug Hawkins
In this talk, we'll walkthrough how the JIT optimizes a piece Java code step-by-step. In doing so, you'll learn some of the amazing feats of optimization that JVMs can perform, but also some surprisingly simple things that prevent your code from running fast.
Java's warm-up challenges are starting to receive more attention lately. For the past 4 years, Azul has been shipping ReadyNow -- a solution to Java's warm-up problems as part of their Zing Virtual Machine.
However in building ReadyNow, Azul chose at unconventional but effective approach to solving these warm-up problems.
This talk is a look into some of the surprising performance cases in Java -- with the goal of illustrating a few simple truths about the nature of compilers.
An overview of the inner-workings of OpenJDK - with emphasis on...
- what triggers the just-in-time compiler (JIT)
- types of speculative optimizations performed by the JIT
- aspects of the Java language & ecosystem that make ahead-of-time (AOT) compilation challenging
JVM Mechanics: When Does the JVM JIT & Deoptimize?Doug Hawkins
HotSpot promises to do the "right" thing for us by identifying our hot code and compiling "just-in-time", but how does HotSpot make those decisions?
This presentation aims to detail how HotSpot makes those decisions and how it corrects its mistakes through a series of demos that you run yourself.
JMeter webinar - integration with InfluxDB and GrafanaRTTS
Watch this recorded webinar about real-time monitoring of application performance. See how to integrate Apache JMeter, the open-source leader in performance testing, with InfluxDB, the open-source time-series database, and Grafana, the open-source analytics and visualization application.
In this webinar, we will review the benefits of leveraging InfluxDB and Grafana when executing load tests and demonstrate how these tools are used to visualize performance metrics.
Length: 30 minutes
Session Overview
-------------------------------------------
During this webinar, we will cover the following topics while demonstrating the integrations of JMeter, InfluxDB and Grafana:
- What out-of-the-box solutions are available for real-time monitoring JMeter tests?
- What are the benefits of integrating InfluxDB and Grafana into the load testing stack?
- Which features are provided by Grafana?
- Demonstration of InfluxDB and Grafana using a practice web application
To view the webinar recording, go to:
https://www.rttsweb.com/jmeter-integration-webinar
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
As AI technology is pushing into IT I was wondering myself, as an “infrastructure container kubernetes guy”, how get this fancy AI technology get managed from an infrastructure operational view? Is it possible to apply our lovely cloud native principals as well? What benefit’s both technologies could bring to each other?
Let me take this questions and provide you a short journey through existing deployment models and use cases for AI software. On practical examples, we discuss what cloud/on-premise strategy we may need for applying it to our own infrastructure to get it to work from an enterprise perspective. I want to give an overview about infrastructure requirements and technologies, what could be beneficial or limiting your AI use cases in an enterprise environment. An interactive Demo will give you some insides, what approaches I got already working for real.
Epistemic Interaction - tuning interfaces to provide information for AI supportAlan Dix
Paper presented at SYNERGY workshop at AVI 2024, Genoa, Italy. 3rd June 2024
https://alandix.com/academic/papers/synergy2024-epistemic/
As machine learning integrates deeper into human-computer interactions, the concept of epistemic interaction emerges, aiming to refine these interactions to enhance system adaptability. This approach encourages minor, intentional adjustments in user behaviour to enrich the data available for system learning. This paper introduces epistemic interaction within the context of human-system communication, illustrating how deliberate interaction design can improve system understanding and adaptation. Through concrete examples, we demonstrate the potential of epistemic interaction to significantly advance human-computer interaction by leveraging intuitive human communication strategies to inform system design and functionality, offering a novel pathway for enriching user-system engagements.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Connector Corner: Automate dynamic content and events by pushing a buttonDianaGray10
Here is something new! In our next Connector Corner webinar, we will demonstrate how you can use a single workflow to:
Create a campaign using Mailchimp with merge tags/fields
Send an interactive Slack channel message (using buttons)
Have the message received by managers and peers along with a test email for review
But there’s more:
In a second workflow supporting the same use case, you’ll see:
Your campaign sent to target colleagues for approval
If the “Approve” button is clicked, a Jira/Zendesk ticket is created for the marketing design team
But—if the “Reject” button is pushed, colleagues will be alerted via Slack message
Join us to learn more about this new, human-in-the-loop capability, brought to you by Integration Service connectors.
And...
Speakers:
Akshay Agnihotri, Product Manager
Charlie Greenberg, Host
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...James Anderson
Effective Application Security in Software Delivery lifecycle using Deployment Firewall and DBOM
The modern software delivery process (or the CI/CD process) includes many tools, distributed teams, open-source code, and cloud platforms. Constant focus on speed to release software to market, along with the traditional slow and manual security checks has caused gaps in continuous security as an important piece in the software supply chain. Today organizations feel more susceptible to external and internal cyber threats due to the vast attack surface in their applications supply chain and the lack of end-to-end governance and risk management.
The software team must secure its software delivery process to avoid vulnerability and security breaches. This needs to be achieved with existing tool chains and without extensive rework of the delivery processes. This talk will present strategies and techniques for providing visibility into the true risk of the existing vulnerabilities, preventing the introduction of security issues in the software, resolving vulnerabilities in production environments quickly, and capturing the deployment bill of materials (DBOM).
Speakers:
Bob Boule
Robert Boule is a technology enthusiast with PASSION for technology and making things work along with a knack for helping others understand how things work. He comes with around 20 years of solution engineering experience in application security, software continuous delivery, and SaaS platforms. He is known for his dynamic presentations in CI/CD and application security integrated in software delivery lifecycle.
Gopinath Rebala
Gopinath Rebala is the CTO of OpsMx, where he has overall responsibility for the machine learning and data processing architectures for Secure Software Delivery. Gopi also has a strong connection with our customers, leading design and architecture for strategic implementations. Gopi is a frequent speaker and well-known leader in continuous delivery and integrating security into software delivery.
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
UiPath Test Automation using UiPath Test Suite series, part 3DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 3. In this session, we will cover desktop automation along with UI automation.
Topics covered:
UI automation Introduction,
UI automation Sample
Desktop automation flow
Pradeep Chinnala, Senior Consultant Automation Developer @WonderBotz and UiPath MVP
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
UiPath Test Automation using UiPath Test Suite series, part 3
Inside Android's Dalvik VM - NEJUG Nov 2011
1. Fo
kr
M
Inside Android’s
e
on
G
itH
ub
Dalvik VM
Douglas Q. Hawkins
http://www.slideshare.net/dougqh
http://github.com/dougqh/nejug2011
http://www.dougqh.net
dougqh@gmail.com
Wednesday, November 9, 11
I’m Doug Hawkins -- interested in VMs -- spoke last year on JVM internals
Spent 6 months learning Dalvik
Ask questions as we go
In addition to being available on SlideShare, all research materials available on GitHub
Slides all have notes and citations for offline reading
2. Android Physiology - Patrick Brady
https://sites.google.com/site/io/anatomy--physiology-of-an-android
Dalvik VM Internals - Dan Bornstein
http://www.youtube.com/watch?v=ptjedOZEXPM
A JIT for Android’s Dalvik VM
Ben Cheng and Bill Buzbee
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Wednesday, November 9, 11
Based on Google IO presentations (mostly from 2008), but updated for the last 3 years
3. ≠
DEX JAR
Dalvik Bytecode Java Bytecode
Wednesday, November 9, 11
Talking about Android
But more specifically talking about how Android and Java are different and why
And, how they are the same and why
4. Different Environments
528 MhZ ARM
192 MB RAM
100 MhZ Bus
32K Cache
No Swap!
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
http://www.gsmarena.com/t_mobile_g1-2533.php
Phone tech lags desktop tech by 10 years
Designed for as little as 70MB of RAM - only 10M left for apps
5. JVMs Problems
Memory Hog
Slow Startup
Wednesday, November 9, 11
Talking about Android
But more specifically talking about how Android and Java are different and why
And, how they are the same and why
6. Not a 10 Year Old OS
Wednesday, November 9, 11
http://en.wikipedia.org/wiki/Java_(programming_language)
Java was released in 1996, when Windows 95 was becoming the dominant OS
While an improvement over Windows 3.1, Windows 95 is not...
- secure
- multi-user
Old Mac OS was not event pre-emptive.
Dalvik gets a boost by depending on a modern OS - Linux
- and custom drivers
7. Dalvik
Wednesday, November 9, 11
http://developer.android.com/guide/basics/what-is-android.html
Went into my research planning to just talk about the Dalvik VM...
...but found that Dalvik is just a piece of a larger puzzle...
...and the rest of the pieces influence Dalvik’s design.
8. Applications
Home Contacts Phone Browser ...
Application Framework
Activity Window Content View Notification
Manager Manager Providers Systems Manager
Package Telephony Resource Location
Manager Manager Manager Manager
Libraries Runtime
Surface Media Core
SQLite OpenGL | ES
Manager Framework Libraries
WebKit SGL SSL bionic - libc Dalvik
Linux Kernel
Display Camera Flash Memory Binder (IPC) Shared
Driver Driver Driver Driver Memory
Power
WebKit SGL SSL
Management
Wednesday, November 9, 11
http://developer.android.com/guide/basics/what-is-android.html
Went into my research planning to just talk about the Dalvik VM...
...but found that Dalvik is just a piece of a larger puzzle...
...and the rest of the pieces influence Dalvik’s design.
9. Legend
Java
Dalvik
Native
OS
Wednesday, November 9, 11
10. Applications
Home Contacts Phone Browser ...
Application Framework
Activity Window Content View Notification
Manager Manager Providers Systems Manager
Package Telephony Resource Location
Manager Manager Manager Manager
Libraries Runtime
Surface Media Core
SQLite OpenGL | ES
Manager Framework Libraries
WebKit SGL SSL bionic - libc Dalvik
Linux Kernel
Display Camera Flash Memory Binder (IPC) Shared
Driver Driver Driver Driver Memory
Power
WebKit SGL SSL
Management
Wednesday, November 9, 11
So, the first part of this talk is about the parts of Android other than Dalvik -- except for
applications --
specifically, Android’s security and IPC mechanisms.
11. ≠
Paranoid Networking
Power Management
Ashmem & Binder
Low Memory Killer
Wednesday, November 9, 11
http://www.lindusembedded.com/blog/2010/12/07/android-linux-kernel-additions/
http://www.kroah.com/log/linux/android-kernel-problems.html
12. Power Management
Screen is off by default
CPU is off by default
“Wake” locks to stay on
Wednesday, November 9, 11
http://developer.android.com/reference/android/os/PowerManager.html
Aggressive approach to power management - CPU and screen off by default
Telephony chip, etc. still responding
“Wake” locks to stay on
13. init.rc
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
14. init.rc
usbd adbd debuggerd rild
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
15. init.rc
usbd
adbd
debuggerd
rild
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
16. init.rc
usbd
adbd zygote
debuggerd
rild
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
17. init.rc
usbd
adbd zygote runtime
debuggerd
rild
Service
Manager
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
18. init.rc
usbd
adbd zygote runtime
debuggerd
rild
Service
Manager
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
19. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Server Manager
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
20. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Server Manager
Surface Audio
Flinger Flinger
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
21. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Server Manager
Surface Audio
Flinger Flinger
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
22. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Server Manager
Surface Audio
Flinger Flinger
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
23. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Server Manager
Surface Audio
Flinger Flinger
Content Telephony Window
Manager Service Manager
Activity Bluetooth
...
Manager Service
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
24. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Server Manager
Surface Audio
Flinger Flinger
Content Telephony Window
Manager Service Manager
Activity Bluetooth
...
Manager Service
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
25. init.rc
usbd
adbd zygote runtime
debuggerd
rild
System Service
Home Server Manager
Surface Audio
Flinger Flinger
Content Telephony Window
Manager Service Manager
Activity Bluetooth
...
Manager Service
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
usbd - usb daemon
adb - android debug bridge
debuggerd - handles process dumps
rild - radio interface layer daemon
runtime - starts the Android service stack
runtime - sends signal to zygote to start System Server
SurfaceFlinger and AudioFlinger - started by System Server
Register back to ServiceManager
Other services started - Java proxies to telephony and bluetooth, etc.
Also register back to ServiceManager
Finally, another signal is sent to zygote and it starts Home
27. Service List
> service list
0 sip: [android.net.sip.ISipService]
1 phone: [com.android.internal.telephony.ITelephony]
2 iphonesubinfo: [com.android.internal.telephony.IPhoneSubInfo]
3 simphonebook: [com.android.internal.telephony.IIccPhoneBook]
4 isms: [com.android.internal.telephony.ISms]
5 samplingprofiler: []
6 diskstats: []
Wednesday, November 9, 11
Service listing shows some of the services that you could see in the previous diagram
28. init.rc
service zygote /system/bin/app_process -Xzygote /system/bin --zygote
--start-system-service
class main
socket zygote stream 666
onrestart write /sys/android_power/request_state wake
onrestart write /sys/power/state on
onrestart restart surfaceflinger
onrestart restart media
Wednesday, November 9, 11
In init.rc, we can see zygote
We can see that its restart triggers surfaceflinger and audioflinger
Also, can see that it sets a wake lock
29. Bionic Harmony
Not glibc!
BSD License Apache License
Small
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
Want to avoid copyleft for benefit of hardware manufacturers
So, use bionic which is from BSD -- not fully glibc compatible -- no exception support -
must use NDK
Harmony instead of standard Java libraries
Not Sun/Oracle certified -- Apache licensed
30. Bionic
Daemon Dalvik Runtime
glibc glibc glibc
Daemon Dalvik Runtime
bionic bionic bionic
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
All processes listed earlier include libc, so using bionic makes everything trimmer
OS on Android -- uses 40MB
Other services -- 20MB
31. What’s Zygote?
Zygote Dalvik ?
Wednesday, November 9, 11
Three forms of Dalvik - normal Dalvik, Zygote, and one to be revealed later
32. Zygote
root
Zygote
Core Libs
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Nascent VM process from which other VM processes are spawned
Already has core libraries loaded in it
Runs as root
When an app is launched, zygote is forked
Fork core libraries are shared with zygote
App code is loaded into the forked VM
Ownership of the process is changed to a user generated for the app at install
Similar to having separate users from apache and mysql on a web server
The zygote means solves both the HotSpot problems: start-up performance and memory
pressure
33. Zygote
root
Zygote Zygote
Core Libs Core Libs
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Nascent VM process from which other VM processes are spawned
Already has core libraries loaded in it
Runs as root
When an app is launched, zygote is forked
Fork core libraries are shared with zygote
App code is loaded into the forked VM
Ownership of the process is changed to a user generated for the app at install
Similar to having separate users from apache and mysql on a web server
The zygote means solves both the HotSpot problems: start-up performance and memory
pressure
34. Zygote
root
Zygote MyApp
Core Libs Core Libs
MyCode
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Nascent VM process from which other VM processes are spawned
Already has core libraries loaded in it
Runs as root
When an app is launched, zygote is forked
Fork core libraries are shared with zygote
App code is loaded into the forked VM
Ownership of the process is changed to a user generated for the app at install
Similar to having separate users from apache and mysql on a web server
The zygote means solves both the HotSpot problems: start-up performance and memory
pressure
35. Zygote
root app_1
Zygote MyApp
Core Libs Core Libs
MyCode
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Nascent VM process from which other VM processes are spawned
Already has core libraries loaded in it
Runs as root
When an app is launched, zygote is forked
Fork core libraries are shared with zygote
App code is loaded into the forked VM
Ownership of the process is changed to a user generated for the app at install
Similar to having separate users from apache and mysql on a web server
The zygote means solves both the HotSpot problems: start-up performance and memory
pressure
36. Zygote
root app_1
Zygote MyApp
Core Libs Core Libs
MyCode
app_2
MyApp2
Core Libs
MyCode
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Nascent VM process from which other VM processes are spawned
Already has core libraries loaded in it
Runs as root
When an app is launched, zygote is forked
Fork core libraries are shared with zygote
App code is loaded into the forked VM
Ownership of the process is changed to a user generated for the app at install
Similar to having separate users from apache and mysql on a web server
The zygote means solves both the HotSpot problems: start-up performance and memory
pressure
37. Clean Dirty
Shared Best Okay
Private Good Bad
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Can split memory across 2-axes: Clean vs Dirty - Shared vs Private
Ideal is Clean - Shared
Core libraries loaded by zygote fall in this category
Can be reloaded by OS at will if need be - shared between processes
Clean - Private is good
This would be your application code -- not shared, but can be reloaded
Shared - Dirty is okay
Core libraries static variables might fall in this category, but split when process alters it
Private - Dirty is bad
Unfortunately, this is only thing you can create, so keep it to a minimum
39. Processes
> ps
USER PID PPID VSIZE NAME
root 67 0 0 binder
system 82 820 272 /system/bin/servicemanager
root 83 4260 852 /system/bin/vold
root 84 4976 708 /system/bin/netd
root 85 684 252 /system/bin/debuggerd
system 86 20884 6900 /system/bin/surfaceflinger
root 87 419512 32228 zygote
app_20 13786 87 26304 com.google.android.apps.maps:NetworkLocationService
app_31 14558 87 25884 com.android.gallery3d
app_45 14571 87 25148 com.google.android.apps.books
app_55 14601 87 29560 com.twitter.android
app_16 16723 87 25384 com.google.android.music
Wednesday, November 9, 11
In this process listing, you can see some of the daemons started at system start
Can see a number of Dalvik processes, each own by its app user and whose parent
process is zygote
40. DB Ownership
USER PID PPID VSIZE NAME
app_50 1782 87 25384 com.google.android.deskclock
> ls /data/data/com.google.android.deskclock/databases
-rw-rw-r-- app_50 app_50 5857 2011-11-06 17:29 alarms.db
-rw-rw-r-- app_50 app_50 153432 2011-11-06 17:23 alarms.db-journal
Wednesday, November 9, 11
A data directory is created for each app...
SQLite databases created by each app are owned by the same user id used when the app
is running
41. Dalvik Does Not Do Security
Warning: security managers do
not provide a secure
environment for executing
untrusted code. Untrusted code
cannot be safely isolated within
the Dalvik VM.
Wednesday, November 9, 11
Because the system handles app isolation, Dalvik does not.
http://developer.android.com/guide/topics/security/security.html
http://developer.android.com/reference/java/lang/SecurityManager.html
43. Ashmem & Binder
Android Shared Memory
Reference Counts
Binder - derived from OpenBinder
From BeOS - OO IPC
Wednesday, November 9, 11
http://www.lindusembedded.com/blog/2010/12/07/android-linux-kernel-additions/
http://www.osnews.com/story/13674/
44. Binder Contacts app_2
Process
My Process app_1
Contacts
My App Service
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
How do apps talk to each other?
Consider “My App” trying to use the “Contacts Service” -- each are running as separate
processes
“My App” uses the “Context” object to locate a service and it gets a reference
However, the object it is given is a proxy managed via Binder
When “My App” tries to invoke “query”, Binder intervenes and marshals the request over
shared memory
However, the request does not go to the main application thread because we don’t that
app or other apps to start
So, the Binder system creates a pool of threads for handling service requests
The “query” method is executed by a service thread, the result is marshalled over shared
memory and ultimately back to “My App”
45. Binder Contacts app_2
Process
My Process app_1
Contacts
My App Context Service
get service
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
How do apps talk to each other?
Consider “My App” trying to use the “Contacts Service” -- each are running as separate
processes
“My App” uses the “Context” object to locate a service and it gets a reference
However, the object it is given is a proxy managed via Binder
When “My App” tries to invoke “query”, Binder intervenes and marshals the request over
shared memory
However, the request does not go to the main application thread because we don’t that
app or other apps to start
So, the Binder system creates a pool of threads for handling service requests
The “query” method is executed by a service thread, the result is marshalled over shared
memory and ultimately back to “My App”
46. Binder Contacts app_2
Process
My Process app_1
Binder Contacts
My App Context Proxy Service
get service
query
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
How do apps talk to each other?
Consider “My App” trying to use the “Contacts Service” -- each are running as separate
processes
“My App” uses the “Context” object to locate a service and it gets a reference
However, the object it is given is a proxy managed via Binder
When “My App” tries to invoke “query”, Binder intervenes and marshals the request over
shared memory
However, the request does not go to the main application thread because we don’t that
app or other apps to start
So, the Binder system creates a pool of threads for handling service requests
The “query” method is executed by a service thread, the result is marshalled over shared
memory and ultimately back to “My App”
47. Binder Contacts app_2
Process
My Process app_1
Binder Contacts
My App Context Proxy Service
get service
query marshalled
over ashmem
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
How do apps talk to each other?
Consider “My App” trying to use the “Contacts Service” -- each are running as separate
processes
“My App” uses the “Context” object to locate a service and it gets a reference
However, the object it is given is a proxy managed via Binder
When “My App” tries to invoke “query”, Binder intervenes and marshals the request over
shared memory
However, the request does not go to the main application thread because we don’t that
app or other apps to start
So, the Binder system creates a pool of threads for handling service requests
The “query” method is executed by a service thread, the result is marshalled over shared
memory and ultimately back to “My App”
48. Binder Contacts app_2
Process
My Process app_1
Binder Contacts
My App Context Proxy Service
get service
query marshalled
over ashmem
Wednesday, November 9, 11
https://sites.google.com/site/io/anatomy--physiology-of-an-android
How do apps talk to each other?
Consider “My App” trying to use the “Contacts Service” -- each are running as separate
processes
“My App” uses the “Context” object to locate a service and it gets a reference
However, the object it is given is a proxy managed via Binder
When “My App” tries to invoke “query”, Binder intervenes and marshals the request over
shared memory
However, the request does not go to the main application thread because we don’t that
app or other apps to start
So, the Binder system creates a pool of threads for handling service requests
The “query” method is executed by a service thread, the result is marshalled over shared
memory and ultimately back to “My App”
50. Different Bytecode
Source
javac
Java Bytecode
dex
DEX
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Android does an extra translation step to a DEX (which is wrapped in an APK)
This is done by the DEX tool (which is actually written in Java)
51. File Format
Constant Pool
Fields
Methods
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
A Java Class file consists of a Constant Pool, Fields, and Methods
Constant Pool is a heterogenous mix of numbers, Strings, class references, method
references, etc.
We might pack a few of these into a JAR file
The problem with this is that common elements (String for example) will be repeated in
all the constant pools.
So, Dalvik takes a different approach. It merges all the constant pools together into a
single constant pool.
Then, it mixes all the fields. Then, all the methods.
This way there’s only a single reference to commonly used classes methods, etc. This
saves space.
Also, the constant pool is not heterogenous mix. It is segmented into strings, then
52. File Format
Constant Pool
A - Fields
A - Methods
Constant Pool
JAR
B - Fields
B - Methods
Constant Pool
C-
C - Methods
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
A Java Class file consists of a Constant Pool, Fields, and Methods
Constant Pool is a heterogenous mix of numbers, Strings, class references, method
references, etc.
We might pack a few of these into a JAR file
The problem with this is that common elements (String for example) will be repeated in
all the constant pools.
So, Dalvik takes a different approach. It merges all the constant pools together into a
single constant pool.
Then, it mixes all the fields. Then, all the methods.
This way there’s only a single reference to commonly used classes methods, etc. This
saves space.
Also, the constant pool is not heterogenous mix. It is segmented into strings, then
53. File Format
Constant Pool
A - Fields Constant
A - Methods Pool
Constant Pool
A - Fields
DEX
JAR
B - Fields B - Fields
B - Methods C - Fields
Constant Pool A - Methods
C- B - Methods
C - Methods C - Methods
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
A Java Class file consists of a Constant Pool, Fields, and Methods
Constant Pool is a heterogenous mix of numbers, Strings, class references, method
references, etc.
We might pack a few of these into a JAR file
The problem with this is that common elements (String for example) will be repeated in
all the constant pools.
So, Dalvik takes a different approach. It merges all the constant pools together into a
single constant pool.
Then, it mixes all the fields. Then, all the methods.
This way there’s only a single reference to commonly used classes methods, etc. This
saves space.
Also, the constant pool is not heterogenous mix. It is segmented into strings, then
54. File Size
Constant Pool Constant Pool
A - Fields A - Fields
A - Methods B - Fields
C - Fields
Constant Pool
DEX
A - Methods
JAR
B - Fields
B - Methods B - Methods
Constant Pool
C - Methods
C-
C - Methods
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
What’s the next effect in terms of size?
Well, DEX save a fair amount of space by having a single constant pool, but, as we’ll see,
Dalvik byte code is a little bigger.
However, JARs are basically ZIPs, so they can be compressed. And, of course, those
repetitions in the constant pools compress well and so does bytecode -- so in the end,
an uncompressed DEX is about the same size as a compressed JAR.
However, the DEX is much easier for the interpreter to work with -- the interpreter can
easily memory map the file and randomly access it -- rather than streaming the file.
55. File Size
Constant Pool Constant Pool
A - Fields A - Fields
A - Methods B - Fields
C - Fields
Constant Pool
DEX
A - Methods
JAR
B - Fields
B - Methods B - Methods
Constant Pool
C - Methods
C-
C - Methods
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
What’s the next effect in terms of size?
Well, DEX save a fair amount of space by having a single constant pool, but, as we’ll see,
Dalvik byte code is a little bigger.
However, JARs are basically ZIPs, so they can be compressed. And, of course, those
repetitions in the constant pools compress well and so does bytecode -- so in the end,
an uncompressed DEX is about the same size as a compressed JAR.
However, the DEX is much easier for the interpreter to work with -- the interpreter can
easily memory map the file and randomly access it -- rather than streaming the file.
56. File Size
Constant Pool Constant Pool
A - Fields A - Fields
A - Methods B - Fields
C - Fields
Constant Pool
JAR
DEX
B - Fields A - Methods
B - Methods
B - Methods
Constant Pool
C-
C - Methods
C - Methods
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
What’s the next effect in terms of size?
Well, DEX save a fair amount of space by having a single constant pool, but, as we’ll see,
Dalvik byte code is a little bigger.
However, JARs are basically ZIPs, so they can be compressed. And, of course, those
repetitions in the constant pools compress well and so does bytecode -- so in the end,
an uncompressed DEX is about the same size as a compressed JAR.
However, the DEX is much easier for the interpreter to work with -- the interpreter can
easily memory map the file and randomly access it -- rather than streaming the file.
57. Java is Stack Based
int foo = 1+2;
foo
0 1 2 3
0 iconst_1
1 iconst_2
2 iadd
3 istore_0
Wednesday, November 9, 11
As you are probably aware, standard JVMs are stack-based.
So, consider the code “int foo = 1 + 2”, this translates to the bytecode shown on the left.
The gray field represents the heap, the column to its right is the stack, and the row
above are the local variable slots.
In regular bytecode, we’d run...
iconst_1 to push 1 onto the stack
iconst_2 to push 2 onto the stack
iadd to sum the 1 and 2 on the stack and store the result 3
istore_0 to store the value in the stack into local variable slot 0 -- namely “foo”
58. Java is Stack Based
int foo = 1+2;
foo
0 1 2 3
0 iconst_1
1 iconst_2
2 iadd
3 istore_0
1
Wednesday, November 9, 11
As you are probably aware, standard JVMs are stack-based.
So, consider the code “int foo = 1 + 2”, this translates to the bytecode shown on the left.
The gray field represents the heap, the column to its right is the stack, and the row
above are the local variable slots.
In regular bytecode, we’d run...
iconst_1 to push 1 onto the stack
iconst_2 to push 2 onto the stack
iadd to sum the 1 and 2 on the stack and store the result 3
istore_0 to store the value in the stack into local variable slot 0 -- namely “foo”
59. Java is Stack Based
int foo = 1+2;
foo
0 1 2 3
0 iconst_1
1 iconst_2
2 iadd
3 istore_0
2
1
Wednesday, November 9, 11
As you are probably aware, standard JVMs are stack-based.
So, consider the code “int foo = 1 + 2”, this translates to the bytecode shown on the left.
The gray field represents the heap, the column to its right is the stack, and the row
above are the local variable slots.
In regular bytecode, we’d run...
iconst_1 to push 1 onto the stack
iconst_2 to push 2 onto the stack
iadd to sum the 1 and 2 on the stack and store the result 3
istore_0 to store the value in the stack into local variable slot 0 -- namely “foo”
60. Java is Stack Based
int foo = 1+2;
foo
0 1 2 3
0 iconst_1
1 iconst_2
2 iadd
3 istore_0
1+2
Wednesday, November 9, 11
As you are probably aware, standard JVMs are stack-based.
So, consider the code “int foo = 1 + 2”, this translates to the bytecode shown on the left.
The gray field represents the heap, the column to its right is the stack, and the row
above are the local variable slots.
In regular bytecode, we’d run...
iconst_1 to push 1 onto the stack
iconst_2 to push 2 onto the stack
iadd to sum the 1 and 2 on the stack and store the result 3
istore_0 to store the value in the stack into local variable slot 0 -- namely “foo”
61. Java is Stack Based
int foo = 1+2;
foo
0 1 2 3
0 iconst_1
1 iconst_2
2 iadd
3 istore_0
3
Wednesday, November 9, 11
As you are probably aware, standard JVMs are stack-based.
So, consider the code “int foo = 1 + 2”, this translates to the bytecode shown on the left.
The gray field represents the heap, the column to its right is the stack, and the row
above are the local variable slots.
In regular bytecode, we’d run...
iconst_1 to push 1 onto the stack
iconst_2 to push 2 onto the stack
iadd to sum the 1 and 2 on the stack and store the result 3
istore_0 to store the value in the stack into local variable slot 0 -- namely “foo”
62. Java is Stack Based
int foo = 1+2;
foo
0 1 2 3
0 iconst_1 3
1 iconst_2
2 iadd
3 istore_0
Wednesday, November 9, 11
As you are probably aware, standard JVMs are stack-based.
So, consider the code “int foo = 1 + 2”, this translates to the bytecode shown on the left.
The gray field represents the heap, the column to its right is the stack, and the row
above are the local variable slots.
In regular bytecode, we’d run...
iconst_1 to push 1 onto the stack
iconst_2 to push 2 onto the stack
iadd to sum the 1 and 2 on the stack and store the result 3
istore_0 to store the value in the stack into local variable slot 0 -- namely “foo”
63. Dalvik is Register Based
int foo = 1+2;
1
st
2
foo
arg
arg
de
0 1 2 3
0 const-4 %r0 1
1 add-int/lit8 %r1 %r0 2
Wednesday, November 9, 11
Dalvik bytecode is register based -- it uses 3-operand form -- which it what a processor
actually uses
To run “int foo = 1 + 2;”, we run...
const-4 to store 1 into register 0
add-int/lit8 to sum the value in register 0 (1) with the literal 2 and store the result into
register 1 -- namely “foo”
This is only 2 dispatches, but Dalvik byte code is measured into 2-byte units
Java byte code was 4-bytes, the Dalvik byte code is actually 6-bytes
However, fewer dispatches generally means less time spent reading code and more time
spent running it by the interpreter
64. Dalvik is Register Based
int foo = 1+2;
1
st
2
foo
arg
arg
de
0 1 2 3
0 const-4 %r0 1 1
1 add-int/lit8 %r1 %r0 2
Wednesday, November 9, 11
Dalvik bytecode is register based -- it uses 3-operand form -- which it what a processor
actually uses
To run “int foo = 1 + 2;”, we run...
const-4 to store 1 into register 0
add-int/lit8 to sum the value in register 0 (1) with the literal 2 and store the result into
register 1 -- namely “foo”
This is only 2 dispatches, but Dalvik byte code is measured into 2-byte units
Java byte code was 4-bytes, the Dalvik byte code is actually 6-bytes
However, fewer dispatches generally means less time spent reading code and more time
spent running it by the interpreter
65. Dalvik is Register Based
int foo = 1+2;
1
st
2
foo
arg
arg
de
0 1 2 3
0 const-4 %r0 1 1 1+2
1 add-int/lit8 %r1 %r0 2
Wednesday, November 9, 11
Dalvik bytecode is register based -- it uses 3-operand form -- which it what a processor
actually uses
To run “int foo = 1 + 2;”, we run...
const-4 to store 1 into register 0
add-int/lit8 to sum the value in register 0 (1) with the literal 2 and store the result into
register 1 -- namely “foo”
This is only 2 dispatches, but Dalvik byte code is measured into 2-byte units
Java byte code was 4-bytes, the Dalvik byte code is actually 6-bytes
However, fewer dispatches generally means less time spent reading code and more time
spent running it by the interpreter
66. Dalvik is Register Based
int foo = 1+2;
1
st
2
foo
arg
arg
de
0 1 2 3
0 const-4 %r0 1 1 3
1 add-int/lit8 %r1 %r0 2
Wednesday, November 9, 11
Dalvik bytecode is register based -- it uses 3-operand form -- which it what a processor
actually uses
To run “int foo = 1 + 2;”, we run...
const-4 to store 1 into register 0
add-int/lit8 to sum the value in register 0 (1) with the literal 2 and store the result into
register 1 -- namely “foo”
This is only 2 dispatches, but Dalvik byte code is measured into 2-byte units
Java byte code was 4-bytes, the Dalvik byte code is actually 6-bytes
However, fewer dispatches generally means less time spent reading code and more time
spent running it by the interpreter
67. Locals
Scratch
Wednesday, November 9, 11
http://www.stanford.edu/class/cs343/resources/java-hotspot.pdf
The way, I’d like you to think about this is...
In a normal VM, local slots are for local variables and stack is scratch space for
computation.
In Dalvik, we just treat them all as registers.
After all, in both VMs, they get mapped back to registers in the end.
In fact, JVMs are not as stack-based as they’d lead you to believe.
Consider, the for loop shown here, it is not legal to do just a push of a number onto the
stack inside a loop in Java byte code.
Why?
Well, to be able map, stack slots to hardware registers, we need the stack height to be
the same at the start and end of a loop -- unlike a true stack-based language like Forth.
The irony is in the end, normal JVMs convert to the same form as Dalvik anyway.
For instance, the HotSpot 6 client JIT works by...
68. Registers
Scratch Locals
Wednesday, November 9, 11
http://www.stanford.edu/class/cs343/resources/java-hotspot.pdf
The way, I’d like you to think about this is...
In a normal VM, local slots are for local variables and stack is scratch space for
computation.
In Dalvik, we just treat them all as registers.
After all, in both VMs, they get mapped back to registers in the end.
In fact, JVMs are not as stack-based as they’d lead you to believe.
Consider, the for loop shown here, it is not legal to do just a push of a number onto the
stack inside a loop in Java byte code.
Why?
Well, to be able map, stack slots to hardware registers, we need the stack height to be
the same at the start and end of a loop -- unlike a true stack-based language like Forth.
The irony is in the end, normal JVMs convert to the same form as Dalvik anyway.
For instance, the HotSpot 6 client JIT works by...
69. Registers
Scratch Locals
JVM JIT
for (int i = 0; i < 100; ++i ) { HIR (SSA)
push(10);
} LIR (3-op)
Machine Code
Wednesday, November 9, 11
http://www.stanford.edu/class/cs343/resources/java-hotspot.pdf
The way, I’d like you to think about this is...
In a normal VM, local slots are for local variables and stack is scratch space for
computation.
In Dalvik, we just treat them all as registers.
After all, in both VMs, they get mapped back to registers in the end.
In fact, JVMs are not as stack-based as they’d lead you to believe.
Consider, the for loop shown here, it is not legal to do just a push of a number onto the
stack inside a loop in Java byte code.
Why?
Well, to be able map, stack slots to hardware registers, we need the stack height to be
the same at the start and end of a loop -- unlike a true stack-based language like Forth.
The irony is in the end, normal JVMs convert to the same form as Dalvik anyway.
For instance, the HotSpot 6 client JIT works by...
70. JVM vs Dalvik
Types Types
int Category1 Normal
float
pointers
long Category2 Wide
double
Wednesday, November 9, 11
The JVM broadly divides types into two categories: 1 & 2
Category 1 types are 32-bit -- these are int, float, and pointers to Objects
Category 2 types are 64-bit -- these are long and double
What about the smaller types: short, byte, char, boolean? -- well in registers they are just
ints
All slots / registers are 32-bit in a normal JVM and Dalvik...
So, 64-bit types take up two registers
Dalvik uses normal and wide to describe these groups, but otherwise things are mostly
the same.
As an aside, the JVM bytecode treats pointers as 32-bits, but the JVM doesn’t always.
A 64-bit JVM may treat them as 64-bit (i.e. Category 2) -- except when it doesn’t
because it uses compressed pointers and puts 2 x 32-bit pointers in a single 64-bit
register
71. JVM vs Dalvik
Bytecode Bytecode
nop nop byte
ifeq / ifne 2-byte if-eqz / if-nez byte 2-byte
iflt / ifle 2-byte if-ltz / if-lez byte 2-byte
ifgt / ifge 2-byte if-gtz / if-gez byte 2-byte
ifnull 2-byte
ifnonnull 2-byte
Wednesday, November 9, 11
Let’s compare some bytecode instructions side-by-side...
In many cases, things are mostly the same...
Regular JVM has a nop -- so does Dalvik, but Dalvik’s takes an extra byte (which is
unused)
Sacrifices space, but makes the interpreter more efficient
Consider the instructions, that compare to zero and jump
Dalvik’s have a hyphen and z at the end, but otherwise they are the same
They do take an extra argument to specify the register to compare against, but that’s it.
However, Dalvik’s if-eqz and if-nez are overloaded. The regular JVM has separate ifnull
and ifnonnull instructions that Dalvik lacks -- it justs if-eqz and if-nez respectively.
72. JVM vs Dalvik
Bytecode Bytecode
iconst_m1 - 5 const4 nibble nibble
bipush byte const16 byte 2-byte
sipush 2-byte const/high16 byte 2-byte
ldc byte const byte 4-byte
istore_0 - 3 move byte byte
istore byte move/from16 byte 2-byte
iload_0 - 3 move/16 2-byte 2-byte
iload byte
Wednesday, November 9, 11
Continuing the comparison, let’s look at loading a number into a slot
JVM bytecode has special instructions inconst_m5 through iconst_5 for values: -1 to 5.
To load into a local variable slot, we’d follow it up with a istore_0 - 3 or a plain istore.
Note, istore takes a byte which indicates that the regular JVM only has 256 local variable
slots.
So, in the end for the common cases: -1 to 5 loaded into slots: 0-3, we use two bytes
and two dispatches.
On Dalvik, we can use const4 which takes a nibble for the destination register and a
nibble for the value.
Worth noting, the nibble for the value is signed so it covers all values -8 to 7.
Also, it can load into register 0-15.
For large values, JVM has ldc which takes a byte, but it is an index into the constant
73. JVM vs Dalvik
Bytecode Bytecode
iget nib nib 2-byte
iget-wide nib nib 2-byte
getfield 2-byte iget-object nib nib 2-byte
iget-short nib nib 2-byte
iget-char nib nib 2-byte
iget-byte nib nib 2-byte
iget-boolean nib nib 2-byte
Wednesday, November 9, 11
Looking at types, a little more sometimes Android is a lot more granular than the JVM.
When loading from an instance field, the JVM has a single instruction: getfield.
Android separates these into iget (for normal), iget-wide, and iget-object, but...
It also has instructions for all the smaller types, too.
74. JVM vs Dalvik
Bytecode Bytecode
iastore aget nib nib 2-byte
fastore
lastore aget-wide nib nib 2-byte
dastore
aastore aget-object nib nib 2-byte
sastore aget-short nib nib 2-byte
castore aget-char nib nib 2-byte
bastore aget-byte nib nib 2-byte
aget-boolean nib nib 2-byte
Wednesday, November 9, 11
...but, sometimes, it goes the other way. The JVM makes a distinction ints and floats
when dealing with arrays, but Android just has aget.
Similarly, for wide types.
They both have instructions for objects, shorts, chars, and bytes, but the regular JVM
does not have an instruction for booleans. In the regular JVM, boolean arrays are
manipulated using byte instructions.
75. Fewer Instructions / Dispatches
Fewer Reads
Fewer Writes
Closer to Machine Code
Wednesday, November 9, 11
The net result...
Byte code is a little bigger, but we do fewer dispatches
We also (at least at the bytecode level), do fewer reads and fewer writes
Also, the bytecode is closer to machine code making the translation a little easier
In the end, the Dalvik interpreter is about twice as efficient as a normal JVM interpreter.
Of course, that’s no real accomplishment, a JIT is orders of magnitude faster in the end.
76. Demo
Compiler API + dex + baksmali
Wednesday, November 9, 11
http://code.google.com/p/smali/
Now, we’re going to look at some Java examples -- shown side-by-side in both Java and
Dalvik
For the ambitious, if you set-up the accompanying Eclipse project and run Serve.
You can use the interactive web-app by directing your browser to localhost:8080/
compile.
These demos are built on-top of Java 6’s compiler API, Android’s dex tool, and DEX
disassembler named baksmali (another Icelandic reference).
77. Hello World
System.out.println("Hello World");
JVM Bytecode Dalvik Bytecode
getstatic System.out sget-object
ldc "Hello World" v0, System.out
invokevirtual const-string
PrintStream.println v1, "Hello World"
invoke-virtual
{v0, v1},
PrintStream.println
Wednesday, November 9, 11
First, let’s start -- where we always start “Hello World”
Both use 3 dispatches -- both use same number of reads and writes
Both jump to constant pool for the string
78. Array
int[] xs = {20, 30, 0, 50};
JVM Bytecode Dalvik Bytecode
iconst_4 // 0x04 const/4 v0, 0x04
newarray int new-array v0, v0, [I
dup fill-array-data
iconst_0 // 0x00 v0, :array_8
bipush 0x14 nop
iastore :array_8
dup 0x14 0x00 0x00 0x00
iconst_1 // 0x01 0x1e 0x00 0x00 0x00
iastore 0x00 0x00 0x00 0x00
dup 0x32 0x00 0x00 0x00
iconst_3 // 0x03
bipush 0x32
iastore
astore_1 // 01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=ptjedOZEXPM
Arrays are particularly inefficient in Java, consider the example above...
For every element, Java adds a dup, an index load, a value push onto the stack, and an
array store.
At best, 4 bytes per element. bipush - immediately pushes it to 5 and gets worse from
there.
For large ints, have to jump to constant pool for the value which provides poor cache
usage.
Android simply has fill-array-data which takes an offset. Data is held close to the code
for better cache utilization. And, that extra nop that’s to align the data on a 4-byte
boundary to make the load that much more efficient.
79. Invoke Static
Math.max(10, 20);
JVM Bytecode Dalvik Bytecode
bipush 0x0a const/16 v0, 0x0a
bipush 0x14 const/16 v1, 0x14
invokestatic Math.max invoke-static
pop {v0, v1}, Math.max
Wednesday, November 9, 11
Looking at invocation of a static method...
Basically, the same - 3 dispatches, but JVM has extra pop at the end
Why, well, the return value of max which was placed on to the stack has to be consumed
somehow, so the JVM adds an extra pop.
Actually, Dalivk does the same thing if you disable optimization, you’ll see a move-result
in the Dalvik bytecode.
However, because this is just a special register, there’s no harm in not moving it, so
Dalvik just gets rid of it.
This highlights another interesting difference Dalvik does compile time optimization.
The regular JVM tool chain used to do this pre-HotSpot, but starting with HotSpot (Java
1.3) optimization purely became the job of the VM.
Since Android uses an interpreter, static optimizations are still useful.
80. New
BigDecimal x = new BigDecimal("2.0");
JVM Bytecode Dalvik Bytecode
new BigDecimal new-instance
dup v0, BigDecimal;
ldc "2.0" const-string
invokespecial v1, "2.0"
BigDecimal.<init> invoke-direct
astore_1 // 01 {v0, v1},
BigDecimal.<init>
Wednesday, November 9, 11
Finally, allocating a new Object.
Allocating a new Object is rather ugly in normal bytecode.
First we allocate a raw slab of memory for the object and place a reference on the stack.
The constructor has not been invoked yet and invoking will consume the reference on
the stack, so we “dup” the reference.
Then invoke the constructor, consuming one reference -- leaving one left that we can
store into a local variable slot.
In Dalvik, it is easier because everything is just a register. The reference we put into the
slot in dispatch 1 is still there when we do the invoke in dispatch 3, so no need for a
“dup”.
JVM has 1w / 1r + 1w / 1w / 2r+1w / 1w -> 3r + 5w
Dalvik has 1w / 1w / 2r + 1w -> 2r + 3w
81. Efficient Interpreter
3rd form of Dalvik
Zygote Dalvik DexOpt
ODEX = Optimized DEX
Wednesday, November 9, 11
The final form of Dalvik -> dexopt - used at install time to make interpreter even more
efficient
82. Installation Process
Extract DEX from APK
dexopt
Verify & Optimize DEX
Chown APK / ODEX to root
Wednesday, November 9, 11
http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html
Not only does Android optimize at translation time, it also optimizes at install time
When the APK is installed, the DEX is extracted from the APK and placed in /data/dalvik-
cache
But it is also optimized -- and optimized to the particular phone
If the file is big endian and the phone is little endian, the endianness is switched
Locking will be handled differently for SMP and non-SMP systems
...and some bytecode optimizations
This addresses performance and launch speed, since verification is only down at install.
More on verification: http://www.milk.com/kodebase/dalvik-docs-mirror/docs/
verifier.html
83. Optimized DEX
invoke-virtual nib 2-byte execute-inline nib nib
java/lang/String#length():I java/lang/String#length():I
invoke-direct nib 2-byte
java/lang/Object#<init>():V
Wednesday, November 9, 11
http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html
Let’s look at just a couple optimizations
First, common operations like String.length have their own special instruction execute-
inline
VM has special code just for those common operations
Things like calling the Object’s constructor - optimized to nothing because the method
is empty
http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html
84. Optimized DEX
CartesianPoint v-table
+x: double +getX(): double
+y: double +getY(): double
-v-table +getRho(): double
+getTheta(): double
iget nib nib 2-byte iget-quick nib nib 2-byte
invoke-virtual nib 2-byte invoke-virtual-quick nib 2-byte
Wednesday, November 9, 11
http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html
Can also do other things because we know how object will be laid out in memory
Can change a field iget to iget-quick which does a simple pointer bump
Can change invoke-virtual to invoke-virtual-quick because we know the layout of the v-table
http://www.netmite.com/android/mydroid/dalvik/docs/dexopt.html
86. DEX-es
> ls /data/dalvik-cache
-rw-r--r-- root root 5857 2011-11-06 17:29 system@app@Maps.apk@classes.dex
-rw-r--r-- root root 153432 2011-11-06 17:23 system@app@Mms.apk@classes.dex
Wednesday, November 9, 11
DEX-es are extracted from APKs and placed in /data/dalvik-cache - owned by root, but
readable by all
87. Device Image ODEX-es
> ls /system/app
-rw-r--r-- root root 5857 2011-11-06 17:29 GoogleBackupTransport.apk
-rw-r--r-- root root 153432 2011-11-06 17:23 GoogleBackupTransport.odex
-rw-r--r-- root root 8575 2011-11-06 17:29 GoogleCalendarSyncAdapter.apk
-rw-r--r-- root root 270752 2011-11-06 17:23 GoogleCalendarSyncAdapter.odex
-rw-r--r-- root root 8563 2011-11-06 17:29 GoogleContactsSyncAdapter.apk
-rw-r--r-- root root 321552 2011-11-06 17:23 GoogleContactsSyncAdapter.odex
Wednesday, November 9, 11
Image ODEX-es are stored next to APK in /system/app
These are generated when the image is being built
88. JIT Compiler
Added in Android 2.2
Clean Dirty
Shared Best Okay
Private Good Bad
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
JIT added in Android 2.2
Why? - hard to make a JIT that does not use private dirty memory - the worse kind
So, memory memory use by using a trace JIT
Also, trace JIT produces performance boost faster
89. JIT Compiler
Added in Android 2.2
Trace - not Method
Memory Pressure
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
JIT added in Android 2.2
Why? - hard to make a JIT that does not use private dirty memory - the worse kind
So, memory memory use by using a trace JIT
Also, trace JIT produces performance boost faster
90. Why a Trace JIT?
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Compiled Code takes up memory - want the benefits of JIT with small memory footprint
Small amount compilation provides a big benefit
In test program, 4.5MB of byte code - 8% of methods: 390K was hot; 25% of code in
methods was hot - so 2% in the end
90% of time in 10% of the code may be generous
91. int signum( int x ) { iload_0 // 00
ifge 0006
if (x > 0) {
return 1;
} else if (x == 0) { iconst_m1 //-01 iload_0 // 00
return 0; ireturn ifne 000c
} else {
return 1;
iconst_0 //00 iconst_1 //01
} ireturn ireturn
}
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Identify the hot blocks
Chain together into a linear code segment
Violating constraints bail to the interpreter
These bails to interpreter are called side exits and exist in all VMs. Since almost every
instruction can potentially raise an exception, treated exceptions at block boundaries
would prevent most useful optimizations. To get around this exceptions are treated as
side exits.
92. int signum( int x ) { iload_0 // 00
ifge 0006
if (x > 0) {
return 1;
} else if (x == 0) { iconst_m1 //-01 iload_0 // 00
return 0; ireturn ifne 000c
} else {
return 1;
iconst_0 //00 iconst_1 //01
} ireturn ireturn
}
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Identify the hot blocks
Chain together into a linear code segment
Violating constraints bail to the interpreter
These bails to interpreter are called side exits and exist in all VMs. Since almost every
instruction can potentially raise an exception, treated exceptions at block boundaries
would prevent most useful optimizations. To get around this exceptions are treated as
side exits.
93. int signum( int x ) { iload_0 // 00
ifge 0006
if (x > 0) {
return 1;
} else if (x == 0) { iload_0 // 00
return 0; BAIL! ifne 000c
} else {
return 1;
iconst_1 //01
} BAIL! ireturn
}
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Identify the hot blocks
Chain together into a linear code segment
Violating constraints bail to the interpreter
These bails to interpreter are called side exits and exist in all VMs. Since almost every
instruction can potentially raise an exception, treated exceptions at block boundaries
would prevent most useful optimizations. To get around this exceptions are treated as
side exits.
94. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
}
return sum;
const/4 v1, 0x00
const/4 v0, 0x00
array-length v3, v0
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
add-int/2addr v2, v3
add-int/lit8
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
95. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler
return sum;
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10
array-length v3, v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v0, v1
add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
96. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler Translation
return sum; Cache
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10 array-lengthv3,v3, v0
array-length v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v0, v1
add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
97. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler Translation
return sum; Cache
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10 array-lengthv3,v3, v0
array-length v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v0, v1
add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
98. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler Translation
return sum; Cache
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10 array-lengthv3,v3, v0
array-length v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v0, v1
add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
99. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler Translation
return sum; Cache
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10 array-lengthv3,v3, v0
array-length v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v3, v0, v1v1
aget
v0,
add-int/2addr v2, v3 add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
100. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler Translation
return sum; Cache
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10 array-lengthv3,v3, v0
array-length v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v3, v0, v1v1
aget
v0,
add-int/2addr v2, v3 add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10
v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
101. int sum = 0;
for (int i=0; i<array.length; ++i) {
sum += array[i];
} Compiler Translation
return sum; Cache
const/4 v1, 0x00
1
const/4 v0, 0x00
array-length v3, v0
10 array-lengthv3,v3, v0
array-length v0
if-ge v1, v3, :cond_c if-ge v1, v3, :cond_c
if-ge v1, v3, :cond_c
return v2 aget v3, v0, v1
10 aget v3, v3, v0, v1v1
aget
v0,
add-int/2addr v2, v3 add-int/2addr v2, v3
add-int/2addr v2, v3
add-int/lit8
10 add-int/lit8
v1, v1, 0x01 v1, v1, 0x01
Wednesday, November 9, 11
http://www.youtube.com/watch?v=Ls0tM-c4Vfo
Keep count for each trace head (i.e. first line of block)
If a block reaches the threshold, hand over for translation
Once compilation is complete, the interpreter starts routing to the generated machine
code
However, not all blocks may be compiled, so control has to return to the interpreter
Eventually, all hot blocks are compiled to machine code -- only the infrequently
executed blocks, the initialization and return continue to be interpreted
102. Performance
Recommendations?
Use Enhanced For Loop
Avoid Creating Objects
Use Native Methods (Judiciously)
Prefer Static Over Virtual
Prefer Virtual Over Interface
Avoid Internal Getters / Setters
Declare Constants Final
Avoid Enums
Use Package Scope with Inner Classes
Avoid Floats
Wednesday, November 9, 11
http://developer.android.com/guide/practices/design/performance.html
There are a lot of performance claims out there, but performance recommendations
typically only last for one or two VM revs.
Earlier Android advice might be just as wrong as early JVM advice is today, let’s see...
103. Demo
+ vogar
Wednesday, November 9, 11
Going to use one of my favorite tools: Caliper for microbenchmarking
Plus vogar, which makes it easy to run all types of tests: VM ref tests, JUnit tests, and
Caliper benchmarks on the Android devices or the emulator
One note of caution these results are from a Xoom which may have a better JIT than an
Android phone
http://code.google.com/p/caliper/
http://code.google.com/p/vogar/
104. String Length
HotSpot Dalvik
String StringBuilder
Wednesday, November 9, 11
First, I wanted to see if the String.length claims were true, so I compared String.length
performance to StringBuilder.length performance
On HotSpot, we can they come out the same, but, on Dalvik, the String.length takes half
the time of StringBuilder.
105. Invocations
HotSpot Dalvik
Static Private Virtual Interface
Wednesday, November 9, 11
The results here are a bit inconclusive, but small methods almost all get inlined in
HotSpot
Even polymorphic calls
In Dalvik, static and private appear to be slightly faster, but it does not make sense that
invoke-virtual is slower than invoke-interface. Although, preferring virtual over
interface seems questionable.
106. Synthetic Access
HotSpot Dalvik
Direct Synthetic
Synthetic
Field Getter Field
Getter
Access Access
Wednesday, November 9, 11
In HotSpot, synthetic access makes little difference (despite the warnings). Synthetic
accessors are smaller than the 15-byte automatic inline threshold, so they make little
difference.
In Dalvik, it is largely the same. Getters get inlined. A synthetic field accessor is just a
getter, so it gets inlined. But, a synthetic method accessor incurs a significant penalty.
107. Loops
HotSpot Dalvik
Primitive Primitive Primitive Boxed
Backwards Enhanced For Tranditional For Enhanced For
Boxed ArrayList ArrayList
Traditional For Thread Unsafe Iterator
Wednesday, November 9, 11
Loops...
Primitive arrays with the new or old for loop perform equally well in both
HotSpot new for reading may be an anomaly.
Definitely, take a hit in both from using a List.
Especially, when using an Iterator - i.e. new for.
108. Enums
HotSpot Dalvik
Primitive Enum
Wednesday, November 9, 11
Somewhat surprisingly at least in relative terms, Dalvik seems to out perform HotSpot
when working when enums