OpenWrt Forum Archive

Topic: java on x86 platform

The content of this topic has been archived on 12 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi,

I'm trying to runa java application (based on the pastry p2p overlay) on a pcengines wrap board.

I've tried both samblevm and jamvm but with not success.

The sablevm package from the kamikaze repo crashes with segmentation fault even with a very simple java app (just hello world). Moreover i get the same segfault with just

java-sablevm -v

I couldn't run jamvm because i do not have the classpath package. Where can i find this package (or just the makefile) for kamikaze?

Thanks
Roberto

jamvm also requires a patch in order to work on the x86 platform. Basically by default jamvm uses 128MB for the heap you can either specify a smaller heap size using the command line:

jamvm -Xmx=8Mb

or (better) you can change the src/jam.h header in order to use another value for the default heap. This is the patch that I;m using:

--- jamvm-1.5.0-old/src/jam.h    2007-10-26 05:08:41.000000000 +0200
+++ jamvm-1.5.0-new/src/jam.h    2008-02-06 10:52:01.000000000 +0100
@@ -676,7 +676,7 @@
 
 /* default maximum size of object heap */
 #ifndef DEFAULT_MAX_HEAP
-#define DEFAULT_MAX_HEAP 128*MB
+#define DEFAULT_MAX_HEAP 8*MB
 #endif
 
 /* default size of the Java stack */

Should I fill a bug to have it checked in the repository?

I managed to properly build a classpath package for openwrt. I'm attaching the makefile in case it could be usefull for someone else.

Would it be possible to have it checked into the kamikaze repository?

include $(TOPDIR)/rules.mk

PKG_NAME:=classpath
PKG_VERSION:=0.96.1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=ftp://ftp.gnu.org/gnu/classpath/

include $(INCLUDE_DIR)/package.mk

define Package/classpath
  SUBMENU:=Java
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=GNU Classpath
  MAINTAINER:=Roberto Riggio (roberto.riggio@gmail.com)
  URL:=http://www.gnu.org/software/classpath/
endef

define Package/classpath/Description 
    GNU Classpath, Essential Libraries for Java, is a GNU project 
    to create free core class libraries for use with virtual 
    machines and compilers for the java programming language.
endef 

CONFIGURE_ARGS+= \
    --with-javac \
    --enable-jni \
    --disable-gtk-peer \
    --disable-gconf-peer \
    --disable-plugin \

define Build/Compile    
    $(MAKE) -C $(PKG_BUILD_DIR) DESTDIR="$(PKG_INSTALL_DIR)" \
        CPPFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
        all install
endef

define Package/classpath/install
    $(INSTALL_DIR) $(1)/usr/local/classpath/lib/classpath
    $(INSTALL_DIR) $(1)/usr/local/classpath/share/classpath
    $(CP) $(PKG_INSTALL_DIR)/usr/lib/classpath/* $(1)/usr/local/classpath/lib/classpath
    $(CP) $(PKG_INSTALL_DIR)/usr/share/classpath/glibj.zip $(1)/usr/local/classpath/share/classpath
endef

$(eval $(call BuildPackage,classpath))

Hello hamvil,

could you please tell me with which Java Compiler you compile the GNU classpath.

And how do one configure jamvm? I'm a little bit confused about the jamvm<VERSION>/lib/classes.zip and the glibj.zip usage.

With best regards,

Sesam

sesam wrote:

Hello hamvil,

could you please tell me with which Java Compiler you compile the GNU classpath.

And how do one configure jamvm? I'm a little bit confused about the jamvm<VERSION>/lib/classes.zip and the glibj.zip usage.

With best regards,

Sesam

Hi,

I'm attaching the make that I'm using to build jamvm. I've made a few change to make it consistent with the makefile that I use to build classpath. I'm using the sun jdk to build classpath. So far everything works fine.

#
# Copyright (C) 2006 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
# $Id: Makefile 10184 2008-01-14 01:47:13Z nbd $

include $(TOPDIR)/rules.mk

PKG_NAME:=jamvm
PKG_VERSION:=1.5.0
PKG_RELEASE:=2

PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz
PKG_SOURCE_URL:=@SF/jamvm
PKG_MD5SUM:=a965452442cdbfc94caba57d0dd25a8f

include $(INCLUDE_DIR)/package.mk

define Package/jamvm
  SUBMENU:=Java
  SECTION:=lang
  CATEGORY:=Languages
  TITLE:=A compact Java Virtual Machine
  URL:=http://sourceforge.net/projects/jamvm
  DEPENDS:=+libffi-sable +libpthread +zlib @!mips @!mipsel
endef

define Package/jamvm/description
 JamVM is a new Java Virtual Machine which conforms to the JVM 
 specification version (blue book). In comparison to most other VM's (free 
 and commercial) it is extremely small.However, unlike other small VMs 
 (e.g. KVM) it is designed to support the full specification, and includes 
 support for object finalisation, Soft/Weak/Phantom References, the Java 
 Native Interface (JNI) and the Reflection API.
endef

CONFIGURE_ARGS+= \
    --enable-ffi \
    --with-classpath-install-dir=/usr \
    --disable-int-threading \

define Build/Compile    
    $(MAKE) -C $(PKG_BUILD_DIR) \
        CPPFLAGS="$(TARGET_CFLAGS) -I$(STAGING_DIR)/usr/include -I$(STAGING_DIR)/include" \
        all
endef

ifneq ($(ARCH),mips)
  define Package/jamvm/install    
    $(INSTALL_DIR) $(1)/usr/bin
    $(INSTALL_BIN) $(PKG_BUILD_DIR)/src/jamvm $(1)/usr/bin/
    $(INSTALL_DIR) $(1)/usr/share/jamvm
    $(INSTALL_DATA) $(PKG_BUILD_DIR)/lib/classes.zip $(1)/usr/share/jamvm/
  endef
endif

$(eval $(call BuildPackage,jamvm))

If you are using it with an x86 device consider also the path that I've posted before to decrease the default heap size.

Hello hamvil,

thank you for sharing your results. I would also suggest to upload your solution to the kamikaze repository.

However, with the current Sun JDK 1.5 relase (JDK 5.0 Update 14) I could not compile the classpath for some reasons. I finally got it using the Eclipse  JDT Core Batch Compiler (Version 3.1.1). So for documenting your results, it would be great if you could post your JDK version.


To force the classpath package to use the Eclipse compiler I add the following configure option as an replacement to your "--with-javac" option:

--with-ecj=/usr/bin/ecj

With /usr/bin/ecj being a little bash-script:

#! /bin/sh

ECJ_JAR=/usr/share/java/ecj.jar
ECJ_MAIN=org.eclipse.jdt.internal.compiler.batch.Main
JAVA_EXEC=java
JAVA_OPTS=-Xmx512M

case $CLASSPATH in
  *${ECJ_JAR}*) ;;
  *) CLASSPATH=${CLASSPATH:+$CLASSPATH:}${ECJ_JAR}
esac
export CLASSPATH

exec ${JAVA_EXEC} ${JAVA_OPTS} ${ECJ_MAIN} ${1+"$@"}

Kind regards,

sesam

sesam wrote:

thank you for sharing your results. I would also suggest to upload your solution to the kamikaze repository.

However, with the current Sun JDK 1.5 relase (JDK 5.0 Update 14) I could not compile the classpath for some reasons. I finally got it using the Eclipse  JDT Core Batch Compiler (Version 3.1.1). So for documenting your results, it would be great if you could post your JDK version.

Hi, i've filled a bug report for jamvm and I've also posted the makefile for classpath on the openwrt-devel maling list, but I've got no answer.

A more general question on jamvm: I've wrote a simple client/server app.However event simply opening a socket on the PCEngines platform take something like
2/3 seconds. Do you also have similiar performance issue with jamvm?

Hello Roberto,

I created a simple server on my PC and a corresponding client on my board running GNU classpath + jamvm + Felix OSGi on it. Here is the output of my client:

1204275489213: new instance of client
1204275489218: started client thread
1204275489229: Opened socket: java.net.Socket@b7738e78 [addr=/xx.xx.xx.xx,port=4455,localport=50692]
1204275489242: Send message
1204275492261: Send message
1204275495271: Send message

with the first column outputted with System.currentTimeMillis(). So as you see, the time to open a socket to a server takes milliseconds....



Afterwards I installed the server on my board and the client on my PC:

1204275489213: new instance of server
1204275925025: started server thread
1204275925033: opened server socket: ServerSocket[addr=/0.0.0.0,port=4455,localport=4455]

...after starting the client on my PC...

1204275972671: accepted client: java.net.Socket@b77d8268 [addr=/xx.xx.xx.xx,port=1459,localport=4455]
1204275972744: received: Here I am!
1204275975671: received: Here I am!


Again, some millis....


Kind regards,

sesam

(Last edited by sesam on 29 Feb 2008, 10:12)

Hi Hamvil and Sesam,

First, thanks for sharing the makefiles for classpath and jamvm! I am using them but experience right now some problems during the compilation towards my broadcom wrt54g device...

/usr/bin/java: line 3: 17149 Segmentation fault    jikes -bootclasspath /usr/lib/kaffe/pthreads/jre/lib/rt.jar ${1+"$@"}

Any ideas how to tackle this?


BTW: Could you tell me how I should configure the menuconfig to have only these two packages built and not the complete image. I already disabled as much as possible in the menu-screen but still it tries to compile much more than only those two packages.

It sounds like a jikes compiling issue due to bad configuration. This is a more detailed error:

*** Semantic Error: You need to modify your classpath, sourcepath, bootclasspath, and/or extdirs setup. Jikes could not find package "java.lang" in:
                ../lib/glibj.zip
                ../tools/tools.zip
                .

Do you have hints on what exactly need to be configured where? Or should I opt for another java compiler?

Kind regards
Ozy

Hello Ozy,

I just found this statement at http://www.gnu.org/software/classpath/docs/hacking.html


4. Project Goals

( ... ) Due to a recent switch to the use of 1.5 language features within GNU Classpath, a compiler compatible with these features is required. At present, this includes the Eclipse compiler, ecj, and the OpenJDK compiler.


So the current classpath (and I think javmvm too) version needs at leat a Java 1.5 compiler. Are you shure that jikes supports java 1.5 language constructs?

Kind regards,

Sesam

Hello to all,

some funny stuff with JamVM:

public class SimpleName {
  public static final void main(String args[]) {
    System.out.println(String.class.getSimpleName());
  }
}

Gives on my PC with Sun's JDK:

String


And on my board with JamVM and the GNU classpath:

java.lang.String

neutral

Kind regards,

Sesam

sesam,
indeed jikes does not support 1.5 constructs (only up to 1.4).
i changed the compiler to sun 1.5 but there was still an error (inconvertable types) which is a bug in sun jdk1.5 and got solved by changing the compiler to 1.6.

However, the "Package/classpath/install" part of the Makefile seems to result in the following error:
cp -fpR /opt/openwrt/kamikaze/build_dir/mipsel/classpath-0.96.1/ipkg-install/usr/lib/classpath/* /opt/openwrt/kamikaze/build_dir/mipsel/classpath-0.96.1/ipkg/classpath/usr/local/classpath/lib/classpath

cp: cannot stat `/opt/openwrt/kamikaze/build_dir/mipsel/classpath-0.96.1/ipkg-install/usr/lib/classpath/*': No such file or directory

Indeed the ipkg-install directory does not exist ...


In fact i do not understand exactly each line in the install part of the Makefile:
define Package/classpath/install
        $(INSTALL_DIR) $(1)/usr/local/classpath/lib/classpath
        $(INSTALL_DIR) $(1)/usr/local/classpath/share/classpath
        $(CP) $(PKG_INSTALL_DIR)/usr/lib/classpath/* $(1)/usr/local/classpath/l$        $(CP) $(PKG_INSTALL_DIR)/usr/share/classpath/glibj.zip $(1)/usr/local/c$endef


Could you explain it?
Thx

Hello ozy,

good to hear that you are nearly finished.

I cannot help you with your problem, because I'm slightly new to the openWRT (and also it's build system). Maybe some of the experienced people here can help you.



Kind regards,

Siamak Haschemi

The discussion might have continued from here.