Skip to content

Commit f0bb5c2

Browse files
wkozaczuknyh
authored andcommitted
Support building and running Java apps in non-isolated mode
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 <[email protected]> Message-Id: <[email protected]>
1 parent 2d8d39c commit f0bb5c2

File tree

4 files changed

+81
-3
lines changed

4 files changed

+81
-3
lines changed

modules/java-non-isolated/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TODO: need to move compilation of $(java-targets) from the main makefile
2+
# to here. Unfortunately, compiling with OSv header files is a big mess,
3+
# and much easier to do it in the main OSv makefile :-(
4+
SRC = $(shell readlink -f ../..)
5+
module:
6+
cd $(SRC)/java && mvn package -DskipTests=true
7+
8+
clean:
9+
cd $(SRC)/java && mvn clean
10+
-rm -f dependency-reduced-pom.xml
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from osv.modules.filemap import FileMap
2+
from osv.modules import api
3+
import os, os.path
4+
5+
usr_files = FileMap()
6+
7+
provides = ['java']
8+
9+
non_isolated_jvm = True
10+
11+
api.require('fonts')
12+
api.require('ca-certificates')
13+
api.require('libz')
14+
api.require('josvsym')
15+
api.require('httpserver-jolokia-plugin')
16+
api.require('httpserver-jvm-plugin')
17+
18+
jdkdir = os.path.basename(os.path.expandvars('${jdkbase}'))
19+
20+
usr_files.add('${jdkbase}').to('/usr/lib/jvm/java') \
21+
.include('lib/**') \
22+
.include('jre/**') \
23+
.exclude('jre/lib/security/cacerts') \
24+
.exclude('jre/lib/audio/**')
25+
26+
usr_files.link('/usr/lib/jvm/' + jdkdir).to('java')
27+
usr_files.link('/usr/lib/jvm/jre').to('java/jre')
28+
usr_files.link('/usr/lib/jvm/java/jre/lib/security/cacerts').to('/etc/pki/java/cacerts')
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#
2+
# Copyright (C) 2013-2014 Cloudius Systems, Ltd.
3+
#
4+
# This work is open source software, licensed under the terms of the
5+
# BSD license as described in the LICENSE file in the top-level directory.
6+
#
7+
8+
[manifest]
9+
/usr/lib/&/libexpat.so.1: %(miscbase)s/usr/lib64/&
10+
/usr/lib/&/libjpeg.so.62: %(miscbase)s/usr/lib64/&
11+
/usr/lib/jni/balloon.so: java/jni/balloon.so
12+
/usr/lib/jni/monitor.so: java/jni/monitor.so
13+
/usr/lib/&/jni/elf-loader.so: java/&
14+
/usr/lib/&/jni/networking.so: java/&
15+
/usr/lib/&/jni/stty.so: java/&
16+
/usr/lib/&/jni/tracepoint.so: java/&
17+
/usr/lib/&/jni/power.so: java/&
18+
/java.so: java/jvm/java_non_isolated.so
19+
/usr/lib/libosv.so: libosv.so
20+
/usr/lib/jvm/java/jre/lib/ext/runjava.jar: ${OSV_BASE}/java/runjava/target/runjava.jar
21+
/java/cloudius.jar: ${OSV_BASE}/java/cloudius/target/cloudius.jar

scripts/module.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from functools import reduce
99
from osv.modules import api, resolve, filemap
1010

11-
class jvm(api.basic_app):
11+
class isolated_jvm(api.basic_app):
1212
multimain_manifest = '/etc/javamains'
1313
apps = []
1414

@@ -33,6 +33,21 @@ def get_launcher_args(self):
3333
def add(self, app):
3434
self.apps.append(app)
3535

36+
def has_any_app(self):
37+
return self.apps
38+
39+
class non_isolated_jvm(api.basic_app):
40+
app = None
41+
42+
def get_launcher_args(self):
43+
return ['java.so'] + self.app.get_jvm_args() + self.app.get_multimain_lines()
44+
45+
def add(self, app):
46+
self.app = app
47+
48+
def has_any_app(self):
49+
return self.app
50+
3651
def expand(text, variables):
3752
def resolve(m):
3853
name = m.group('name')
@@ -117,7 +132,11 @@ def flatten_list(elememnts):
117132

118133
def get_basic_apps(apps):
119134
basic_apps = []
120-
_jvm = jvm()
135+
java = resolve.require('java')
136+
if hasattr(java,'non_isolated_jvm') and java.non_isolated_jvm:
137+
_jvm = non_isolated_jvm()
138+
else:
139+
_jvm = isolated_jvm()
121140

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

130-
if _jvm.apps:
149+
if _jvm.has_any_app():
131150
basic_apps.append(_jvm)
132151

133152
return basic_apps

0 commit comments

Comments
 (0)