Skip to content

Commit

Permalink
Support building and running Java apps in non-isolated mode
Browse files Browse the repository at this point in the history
Added new java-non-isolated module and refactored
 scripts/module.py to provide isolated_jvm and non_isolated_jvm as a way to
 build and run java apps in isolated (old default) and non-isolated mode.

The non-isolated mode gets enabled by module.py that detects if selected
 java module (provides = ['java']) has following attribute set to true like so:

non_isolated_jvm = True

Example to build an image with isolated JVM (default):
./scripts/build image=java,java-example

Example to build an image with non-isolated JVM:
./scripts/build image=java-non-isolated,java-example

Fixes #800

Signed-off-by: Waldemar Kozaczuk <jwkozaczuk@gmail.com>
Message-Id: <1476475985-1980-1-git-send-email-jwkozaczuk@gmail.com>
  • Loading branch information
wkozaczuk authored and nyh committed Nov 2, 2016
1 parent 2d8d39c commit f0bb5c2
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 3 deletions.
10 changes: 10 additions & 0 deletions modules/java-non-isolated/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# TODO: need to move compilation of $(java-targets) from the main makefile
# to here. Unfortunately, compiling with OSv header files is a big mess,
# and much easier to do it in the main OSv makefile :-(
SRC = $(shell readlink -f ../..)
module:
cd $(SRC)/java && mvn package -DskipTests=true

clean:
cd $(SRC)/java && mvn clean
-rm -f dependency-reduced-pom.xml
28 changes: 28 additions & 0 deletions modules/java-non-isolated/module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from osv.modules.filemap import FileMap
from osv.modules import api
import os, os.path

usr_files = FileMap()

provides = ['java']

non_isolated_jvm = True

api.require('fonts')
api.require('ca-certificates')
api.require('libz')
api.require('josvsym')
api.require('httpserver-jolokia-plugin')
api.require('httpserver-jvm-plugin')

jdkdir = os.path.basename(os.path.expandvars('${jdkbase}'))

usr_files.add('${jdkbase}').to('/usr/lib/jvm/java') \
.include('lib/**') \
.include('jre/**') \
.exclude('jre/lib/security/cacerts') \
.exclude('jre/lib/audio/**')

usr_files.link('/usr/lib/jvm/' + jdkdir).to('java')
usr_files.link('/usr/lib/jvm/jre').to('java/jre')
usr_files.link('/usr/lib/jvm/java/jre/lib/security/cacerts').to('/etc/pki/java/cacerts')
21 changes: 21 additions & 0 deletions modules/java-non-isolated/usr.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (C) 2013-2014 Cloudius Systems, Ltd.
#
# This work is open source software, licensed under the terms of the
# BSD license as described in the LICENSE file in the top-level directory.
#

[manifest]
/usr/lib/&/libexpat.so.1: %(miscbase)s/usr/lib64/&
/usr/lib/&/libjpeg.so.62: %(miscbase)s/usr/lib64/&
/usr/lib/jni/balloon.so: java/jni/balloon.so
/usr/lib/jni/monitor.so: java/jni/monitor.so
/usr/lib/&/jni/elf-loader.so: java/&
/usr/lib/&/jni/networking.so: java/&
/usr/lib/&/jni/stty.so: java/&
/usr/lib/&/jni/tracepoint.so: java/&
/usr/lib/&/jni/power.so: java/&
/java.so: java/jvm/java_non_isolated.so
/usr/lib/libosv.so: libosv.so
/usr/lib/jvm/java/jre/lib/ext/runjava.jar: ${OSV_BASE}/java/runjava/target/runjava.jar
/java/cloudius.jar: ${OSV_BASE}/java/cloudius/target/cloudius.jar
25 changes: 22 additions & 3 deletions scripts/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from functools import reduce
from osv.modules import api, resolve, filemap

class jvm(api.basic_app):
class isolated_jvm(api.basic_app):
multimain_manifest = '/etc/javamains'
apps = []

Expand All @@ -33,6 +33,21 @@ def get_launcher_args(self):
def add(self, app):
self.apps.append(app)

def has_any_app(self):
return self.apps

class non_isolated_jvm(api.basic_app):
app = None

def get_launcher_args(self):
return ['java.so'] + self.app.get_jvm_args() + self.app.get_multimain_lines()

def add(self, app):
self.app = app

def has_any_app(self):
return self.app

def expand(text, variables):
def resolve(m):
name = m.group('name')
Expand Down Expand Up @@ -117,7 +132,11 @@ def flatten_list(elememnts):

def get_basic_apps(apps):
basic_apps = []
_jvm = jvm()
java = resolve.require('java')
if hasattr(java,'non_isolated_jvm') and java.non_isolated_jvm:
_jvm = non_isolated_jvm()
else:
_jvm = isolated_jvm()

for app in flatten_list(apps):
if isinstance(app, api.basic_app):
Expand All @@ -127,7 +146,7 @@ def get_basic_apps(apps):
else:
raise Exception("Unknown app type: " + str(app))

if _jvm.apps:
if _jvm.has_any_app():
basic_apps.append(_jvm)

return basic_apps
Expand Down

0 comments on commit f0bb5c2

Please sign in to comment.