SlideShare a Scribd company logo
Dr Andy Piper | Oracle Corp.
OSGi and Android
- or how to train your
appserver
Disclaimer
• The opinions represented in these
slides are entirely my own not
Oracle’s
• These slides do not represent any
kind of indication of or commitment
to Oracle’s future products or future
product strategy
Me
• Dr Andy Piper, MA, MBA
• Software architect and engineering
manager for Oracle Complex Event
Processing at Oracle
• ex-BEA, WebLogic Server core
architect
• Author “Spring Dynamic Modules in
Action”
Background
• Android supports Java
– But what does this really mean?
• OSGi has been shown to run on
Android
– Equinox on OSGi at EclipseCon ’08
(Bartlett/IBM)
– Felix on OSGi with EZDroid
(Luminis)
– Various commercial offerings
Don’t cross the streams!
• No-one appears to be trying any
full-fat apps on Android (i.e. non-
phone apps)
• What happens if you try something
big – like an application server, say?
• What problems do you run into?
The challenger
• OCEP
– OSGi-based appserver (a bit like Virgo)
– Spring
– Spring DM
– Glassfish JAXB
– Jetty
– Hessian
– JCL
– Commonj
– And much more …
The challenger at the weigh-in
• Default OCEP installation:
– 224 OSGi bundles
– 125 Mb on-disk
– 162 Mb in-memory
• OCEP re-factored to create a minimal set
of bundles
– Straightforward thanks to OSGi
– Supports a helloworld application, but
not much else
– 113 bundles
– 24 Mb on-disk
– 92 Mb in-memory
Android
• Google Phone OS
• Linux-based kernel and utilities
• Applications are written in Java
– Dalvik VM runs applications
•One VM per-application - no JIT! (except
2.2)
– Proprietary bytecode format
•Optimized for small CPU & memory
footprint
•Java bytecode can be translated
– Package profile similar to Java ME
•Many features missing, e.g. JNDI, parts of
javax.xml, JMX and other enterprise
features
•Based on Apache Harmony class libraries
Android & OSGi
• Dalvik does not support dynamic class
definition
– Problem for OSGi, but there are some
workarounds
• Felix (Apache) now works
– Work by Luminis
– EZdroid project based on Apache ACE
• Equinox demonstrated at EclipseCon 08
– Fixes do not work with latest Android
and Equinox
– But can be made to work
• Other commercial offerings available
OCEP on Android
• OCEP re-packaged as dalvik
bytecode jars
• Equinox issues resolved
• Minimal feature-set bundles will all
install on Android emulator (256Mb
RAM, 256Mb flash)
• But there many problems …
Problems with dalvik profile
• Problem is the missing packages in the
dalvik profile
– For instance OCEP relies on Java SE XML
features not present in profile
– Very hard to simulate since some are in
java.*
• In theory this can be worked around by
providing the packages
– Add xerces
– Add Sun 1.2 JNDI impl
– Add mx4j
• But the list is quite large
Developing a dalvik profile
• Easy to test without Android!
– -Dosgi.java.profile allows the
profile of any VM to be limited
•Still does not simulate missing
java.* packages
– We have a Dalvik profile
– If it works on Windows/Linux it
may work on Dalvik
• We have a small footprint profile as
a starting point
Really, really small profile
• JMX gone (no RMI)
• RMI gone (no RMI OP
implementations)
• JNDI gone (no RMI)
• cglib gone (no dynamic class
definition in Dalvik)
• JMS gone
• datasource gone (too many
dependencies)
Even with the small profile
• Missing packages cause problems
– java.rmi
– java.beans (some of; related to awt & swing)
– javax.security.auth
– javax.management
– javax.naming
– javax.annotation
– javax.xml.validation & friends
– java.sql.SQLXML
• javax outages can be fixed through apache
libraries
• java outages more tricky
Start hacking!
• java.rmi
– Engine dependent on Remote & RemoteException
• Package these up, but ideally factor out
dependency
– Config requires java.rmi.dgc
• Package up, but need to factor out
• java.beans
– Particularly problematic. Android includes some
classes
• But not the useful ones (heavily used by Spring)!
– Take harmony impl and hack out awt & swing
references
– Recompile & package up
• Both need to be included on bootclasspath
More hacking
• java.sql.SQLXML
– Can make the dependency dynamic through
Class.forName()
• XML parser problems
– Cannot use Android and xerces together
– Have to completely replace implementation
– Implementation has assumptions about the
ContextClassLoader
•Hack Factory’s to fallback to bundle
classloader (changes submitted to apache)
– Compiled versions contain bad bytecode!
•Recompile
… and more …
• JAXB Problems
– Contains marshalling support for types
that do not exist on Android
•Hack to remove these dependencies
– Issues with classloading (JAXB or
Harmony bug)
•DynamicImport-Package: *
– Dalvik hasn't implemented
Package.getDeclaredAnnotations()
•Get a LinkageError
•Hack JAXB to remove dependency
… and finally
• Dalvik doesn’t like null as a parent classloader
– Hack Spring DM and Equinox to remove
(changes kindly incorporated by Thomas
Watson)
• Bundle.getResources() can return null which is
not the same semantic as
ClassLoader.findResources()
– Hack Spring DM and Equinox to return empty
collection
• Many missing imports when classloading is
more strict
• Logging requires boot delegation for META-
INF.services to work
But it works!
• 12 extra bundles/jars
– 3 vanilla SpringSource EBR
bundles
– 9 custom patched bundles/jars
• A few Android specific hooks in the
product
– Disable JMX
– Disable cglib
But…
• It’s really slow
– The JIT blows up if you try it (not
tried later JITs)
– Java ME JIT is typically 6x faster
than interpreted code
• It’s really hard to debug
– You can attach remotely
– But the emulator blows up a lot
– Did I mention it’s slow?
The good
• If your application runs on OSGi,
refactoring for footprint is relatively
easy
• Equinox profiles makes testing easy
• Linux/Java on a phone makes for a
very low developer barrier to entry
(contrast with other platforms)
• You can run a full-fat application on
Android/Dalvik
• Non-Dalvik offerings (e.g. Java ME)
are in the works
The bad & ugly
• Android class libraries are just
broken
– What were they thinking!
– Need to support some recognized
VM profile or recognized subset
– Standardization is necessary
• Dalvik VM limitations are a
significant hindrance to
development
Questions?
• Contact: andy.piper@oracle.com

More Related Content

PDF
History of Java 1/2
PDF
Social Connections 2015 CrossWorlds and Domino
PDF
itft-Java evolution
PDF
DevNexus 2019: Migrating to Java 11
PDF
Migration tales from java ee 5 to 7
PDF
Java 8 in Anger (JavaOne)
PDF
KYSUC - Keep Your Schema Under Control
PDF
Kaunas JUG#1: Java History and Trends (Dainius Mezanskas)
History of Java 1/2
Social Connections 2015 CrossWorlds and Domino
itft-Java evolution
DevNexus 2019: Migrating to Java 11
Migration tales from java ee 5 to 7
Java 8 in Anger (JavaOne)
KYSUC - Keep Your Schema Under Control
Kaunas JUG#1: Java History and Trends (Dainius Mezanskas)

What's hot (20)

PPTX
Migrating to Java 11
PPTX
Scala in the Wild
PPT
01 java intro
ODP
Eureka moment
PDF
Scala
PDF
Maven - Taming the Beast
PDF
Whats new in Java 9,10,11,12
PPT
Evolution Of Java
KEY
Fun with EJB 3.1 and Open EJB
PDF
Java EE and Google App Engine
PPTX
Preparing for java 9 modules upload
PPTX
Java basics at Lara Technologies
PPTX
Hybrid Mobile Development with Apache Cordova and
PDF
Scala introduction
DOC
Selenium Classroom Training
PPT
Java SE 7 New Features and Enhancements
PDF
20140228 fp and_performance
PDF
Javantura v4 - JVM++ The GraalVM - Martin Toshev
PDF
Develop realtime web with Scala and Xitrum
PPT
Migrating to Java 11
Scala in the Wild
01 java intro
Eureka moment
Scala
Maven - Taming the Beast
Whats new in Java 9,10,11,12
Evolution Of Java
Fun with EJB 3.1 and Open EJB
Java EE and Google App Engine
Preparing for java 9 modules upload
Java basics at Lara Technologies
Hybrid Mobile Development with Apache Cordova and
Scala introduction
Selenium Classroom Training
Java SE 7 New Features and Enhancements
20140228 fp and_performance
Javantura v4 - JVM++ The GraalVM - Martin Toshev
Develop realtime web with Scala and Xitrum
Ad

Viewers also liked (9)

PDF
AMA Using Blogging As A Weapon
PDF
OSGi DevCon US 2010 Review
PDF
AMA SIG Social Media 11-4-09
PPT
InnoGage Earth Day 2009
PDF
InnoGage KASCAC Presentation
PDF
OSGi Users' Forum UK - OSGi Release 4 v4.2 Spec Overview - Peter Kriens
PPTX
Blogs & Content Marketing
PDF
InnoGage EduWeb Conference UGC - Tapping The Power
PDF
The Six Highest Performing B2B Blog Post Formats
AMA Using Blogging As A Weapon
OSGi DevCon US 2010 Review
AMA SIG Social Media 11-4-09
InnoGage Earth Day 2009
InnoGage KASCAC Presentation
OSGi Users' Forum UK - OSGi Release 4 v4.2 Spec Overview - Peter Kriens
Blogs & Content Marketing
InnoGage EduWeb Conference UGC - Tapping The Power
The Six Highest Performing B2B Blog Post Formats
Ad

Similar to OSGi Community Event 2010 - OSGi and Android (20)

KEY
Introduction to Java 7 (OSCON 2012)
PPTX
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
PDF
Java 9, JShell, and Modularity
PPT
01-Introduction.ppt
PPTX
Leaner microservices with Java 10
PDF
Jax london 2011
PDF
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
PPTX
Java Basics
PPT
The Evolution of Java
PDF
Create *real* modular Java applications - a brief introduction -
PDF
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
PDF
Mobile Fest 2018. Алексей Лизенко. Make your project great again
PPTX
JAVA_Day1_BasicIntroduction.pptx
PPTX
JAVAPart1_BasicIntroduction.pptx
PDF
Calling All Modularity Solutions: A Comparative Study from eBay
PPTX
Java introduction by lara technologies
PDF
Calling all modularity solutions
PDF
Clojure in real life 17.10.2014
PDF
1java Introduction
Introduction to Java 7 (OSCON 2012)
Modules in Java? Finally! (OpenJDK 9 Jigsaw, JSR376)
Java 9, JShell, and Modularity
01-Introduction.ppt
Leaner microservices with Java 10
Jax london 2011
Java Core | Java 8 and OSGi Modularisation | Tim Ellison & Neil Bartlett
Java Basics
The Evolution of Java
Create *real* modular Java applications - a brief introduction -
Java 9 / Jigsaw - LJC / VJUG session (hackday session)
Mobile Fest 2018. Алексей Лизенко. Make your project great again
JAVA_Day1_BasicIntroduction.pptx
JAVAPart1_BasicIntroduction.pptx
Calling All Modularity Solutions: A Comparative Study from eBay
Java introduction by lara technologies
Calling all modularity solutions
Clojure in real life 17.10.2014
1java Introduction

More from mfrancis (20)

PDF
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
PDF
OSGi and Java 9+ - BJ Hargrave (IBM)
PDF
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
PDF
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
PDF
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
PDF
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
PDF
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
PDF
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
PDF
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
PDF
OSGi CDI Integration Specification - Ray Augé (Liferay)
PDF
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
PDF
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
PDF
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
PDF
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
PDF
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
PDF
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
PDF
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
PDF
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
PDF
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
PDF
How to connect your OSGi application - Dirk Fauth (Bosch)
Eclipse Modeling Framework and plain OSGi the easy way - Mark Hoffman (Data I...
OSGi and Java 9+ - BJ Hargrave (IBM)
Simplify Web UX Coding using OSGi Modularity Magic - Paul Fraser (A2Z Living)
OSGi for the data centre - Connecting OSGi to Kubernetes - Frank Lyaruu
Remote Management and Monitoring of Distributed OSGi Applications - Tim Verbe...
OSGi with Docker - a powerful way to develop Java systems - Udo Hafermann (So...
A real world use case with OSGi R7 - Jurgen Albert (Data In Motion Consulting...
OSGi Feature Model - Where Art Thou - David Bosschaert (Adobe)
Migrating from PDE to Bndtools in Practice - Amit Kumar Mondal (Deutsche Tele...
OSGi CDI Integration Specification - Ray Augé (Liferay)
How OSGi drives cross-sector energy management - Jörn Tümmler (SMA Solar Tech...
Improved developer productivity thanks to Maven and OSGi - Lukasz Dywicki (Co...
It Was Twenty Years Ago Today - Building an OSGi based Smart Home System - Ch...
Popular patterns revisited on OSGi - Christian Schneider (Adobe)
Integrating SLF4J and the new OSGi LogService 1.4 - BJ Hargrave (IBM)
OSG(a)i: because AI needs a runtime - Tim Verbelen (imec)
Flying to Jupiter with OSGi - Tony Walsh (ESA) & Hristo Indzhov (Telespazio V...
MicroProfile, OSGi was meant for this - Ray Auge (Liferay)
Prototyping IoT systems with a hybrid OSGi & Node-RED platform - Bruce Jackso...
How to connect your OSGi application - Dirk Fauth (Bosch)

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Electronic commerce courselecture one. Pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
cuic standard and advanced reporting.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Reach Out and Touch Someone: Haptics and Empathic Computing
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Building Integrated photovoltaic BIPV_UPV.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MYSQL Presentation for SQL database connectivity
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The Rise and Fall of 3GPP – Time for a Sabbatical?
Electronic commerce courselecture one. Pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
The AUB Centre for AI in Media Proposal.docx
Unlocking AI with Model Context Protocol (MCP)
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton

OSGi Community Event 2010 - OSGi and Android

  • 1. Dr Andy Piper | Oracle Corp. OSGi and Android - or how to train your appserver
  • 2. Disclaimer • The opinions represented in these slides are entirely my own not Oracle’s • These slides do not represent any kind of indication of or commitment to Oracle’s future products or future product strategy
  • 3. Me • Dr Andy Piper, MA, MBA • Software architect and engineering manager for Oracle Complex Event Processing at Oracle • ex-BEA, WebLogic Server core architect • Author “Spring Dynamic Modules in Action”
  • 4. Background • Android supports Java – But what does this really mean? • OSGi has been shown to run on Android – Equinox on OSGi at EclipseCon ’08 (Bartlett/IBM) – Felix on OSGi with EZDroid (Luminis) – Various commercial offerings
  • 5. Don’t cross the streams! • No-one appears to be trying any full-fat apps on Android (i.e. non- phone apps) • What happens if you try something big – like an application server, say? • What problems do you run into?
  • 6. The challenger • OCEP – OSGi-based appserver (a bit like Virgo) – Spring – Spring DM – Glassfish JAXB – Jetty – Hessian – JCL – Commonj – And much more …
  • 7. The challenger at the weigh-in • Default OCEP installation: – 224 OSGi bundles – 125 Mb on-disk – 162 Mb in-memory • OCEP re-factored to create a minimal set of bundles – Straightforward thanks to OSGi – Supports a helloworld application, but not much else – 113 bundles – 24 Mb on-disk – 92 Mb in-memory
  • 8. Android • Google Phone OS • Linux-based kernel and utilities • Applications are written in Java – Dalvik VM runs applications •One VM per-application - no JIT! (except 2.2) – Proprietary bytecode format •Optimized for small CPU & memory footprint •Java bytecode can be translated – Package profile similar to Java ME •Many features missing, e.g. JNDI, parts of javax.xml, JMX and other enterprise features •Based on Apache Harmony class libraries
  • 9. Android & OSGi • Dalvik does not support dynamic class definition – Problem for OSGi, but there are some workarounds • Felix (Apache) now works – Work by Luminis – EZdroid project based on Apache ACE • Equinox demonstrated at EclipseCon 08 – Fixes do not work with latest Android and Equinox – But can be made to work • Other commercial offerings available
  • 10. OCEP on Android • OCEP re-packaged as dalvik bytecode jars • Equinox issues resolved • Minimal feature-set bundles will all install on Android emulator (256Mb RAM, 256Mb flash) • But there many problems …
  • 11. Problems with dalvik profile • Problem is the missing packages in the dalvik profile – For instance OCEP relies on Java SE XML features not present in profile – Very hard to simulate since some are in java.* • In theory this can be worked around by providing the packages – Add xerces – Add Sun 1.2 JNDI impl – Add mx4j • But the list is quite large
  • 12. Developing a dalvik profile • Easy to test without Android! – -Dosgi.java.profile allows the profile of any VM to be limited •Still does not simulate missing java.* packages – We have a Dalvik profile – If it works on Windows/Linux it may work on Dalvik • We have a small footprint profile as a starting point
  • 13. Really, really small profile • JMX gone (no RMI) • RMI gone (no RMI OP implementations) • JNDI gone (no RMI) • cglib gone (no dynamic class definition in Dalvik) • JMS gone • datasource gone (too many dependencies)
  • 14. Even with the small profile • Missing packages cause problems – java.rmi – java.beans (some of; related to awt & swing) – javax.security.auth – javax.management – javax.naming – javax.annotation – javax.xml.validation & friends – java.sql.SQLXML • javax outages can be fixed through apache libraries • java outages more tricky
  • 15. Start hacking! • java.rmi – Engine dependent on Remote & RemoteException • Package these up, but ideally factor out dependency – Config requires java.rmi.dgc • Package up, but need to factor out • java.beans – Particularly problematic. Android includes some classes • But not the useful ones (heavily used by Spring)! – Take harmony impl and hack out awt & swing references – Recompile & package up • Both need to be included on bootclasspath
  • 16. More hacking • java.sql.SQLXML – Can make the dependency dynamic through Class.forName() • XML parser problems – Cannot use Android and xerces together – Have to completely replace implementation – Implementation has assumptions about the ContextClassLoader •Hack Factory’s to fallback to bundle classloader (changes submitted to apache) – Compiled versions contain bad bytecode! •Recompile
  • 17. … and more … • JAXB Problems – Contains marshalling support for types that do not exist on Android •Hack to remove these dependencies – Issues with classloading (JAXB or Harmony bug) •DynamicImport-Package: * – Dalvik hasn't implemented Package.getDeclaredAnnotations() •Get a LinkageError •Hack JAXB to remove dependency
  • 18. … and finally • Dalvik doesn’t like null as a parent classloader – Hack Spring DM and Equinox to remove (changes kindly incorporated by Thomas Watson) • Bundle.getResources() can return null which is not the same semantic as ClassLoader.findResources() – Hack Spring DM and Equinox to return empty collection • Many missing imports when classloading is more strict • Logging requires boot delegation for META- INF.services to work
  • 19. But it works! • 12 extra bundles/jars – 3 vanilla SpringSource EBR bundles – 9 custom patched bundles/jars • A few Android specific hooks in the product – Disable JMX – Disable cglib
  • 20. But… • It’s really slow – The JIT blows up if you try it (not tried later JITs) – Java ME JIT is typically 6x faster than interpreted code • It’s really hard to debug – You can attach remotely – But the emulator blows up a lot – Did I mention it’s slow?
  • 21. The good • If your application runs on OSGi, refactoring for footprint is relatively easy • Equinox profiles makes testing easy • Linux/Java on a phone makes for a very low developer barrier to entry (contrast with other platforms) • You can run a full-fat application on Android/Dalvik • Non-Dalvik offerings (e.g. Java ME) are in the works
  • 22. The bad & ugly • Android class libraries are just broken – What were they thinking! – Need to support some recognized VM profile or recognized subset – Standardization is necessary • Dalvik VM limitations are a significant hindrance to development