first pass at Android classpath support

Stuff compiles, but linking breaks spectacularly.  Next step is to
figure out how to build the dependencies without checking out and
building the entire Android platform.
This commit is contained in:
Joel Dice 2013-02-19 09:36:19 -07:00
parent fd0b2b844b
commit 0f524fcf16
3 changed files with 242 additions and 4 deletions

View File

@ -148,6 +148,41 @@ ifneq ($(openjdk),)
build-javahome = $(openjdk)/jre
endif
ifneq ($(android),)
options := $(options)-android
classpath-jar-dep = $(build)/android.dep
luni-native = $(android)/libcore/luni/src/main/native
android-cflags := -I$(luni-native) \
-I$(android)/libnativehelper/include/nativehelper \
-I$(android)/core/include \
-I$(android)/zlib \
-I$(android)/icu4c/i18n \
-I$(android)/icu4c/common \
-I$(android)/expat \
-I$(android)/openssl/include \
-I$(android)/libcore/include \
-I$(build)/android-src/external/fdlibm \
-I$(build)/android-src \
-fpermissive \
-fno-exceptions \
-DHAVE_SYS_UIO_H \
-D_FILE_OFFSET_BITS=64
luni-cpps := $(shell find $(luni-native) -name '*.cpp')
classpath-objects = \
$(call cpp-objects,$(luni-cpps),$(luni-native),$(build))
luni-java = $(android)/libcore/luni/src/main/java
luni-javas := $(shell find $(luni-java) -name '*.java')
dalvik-java = $(android)/libcore/dalvik/src/main/java
dalvik-javas := $(shell find $(dalvik-java) -name '*.java')
xml-java = $(android)/libcore/xml/src/main/java
xml-javas := $(shell find $(xml-java) -name '*.java')
android-classes = \
$(call java-classes,$(luni-javas),$(luni-java),$(build)/android) \
$(call java-classes,$(dalvik-javas),$(dalvik-java),$(build)/android) \
$(call java-classes,$(xml-javas),$(xml-java),$(build)/android)
classpath = android
endif
ifeq ($(classpath),avian)
jni-sources := $(shell find $(classpath-src) -name '*.cpp')
jni-objects = $(call cpp-objects,$(jni-sources),$(classpath-src),$(build))
@ -1178,6 +1213,11 @@ ifneq ($(classpath),avian)
ifneq ($(openjdk),)
classpath-sources := $(classpath-sources) \
$(classpath-src)/avian/OpenJDK.java
else
classpath-sources := $(classpath-sources) \
$(classpath-src)/sun/reflect/ConstantPool.java \
$(classpath-src)/java/lang/ReflectiveOperationException.java \
$(classpath-src)/sun/misc/Cleaner.java
endif
else
classpath-sources := $(shell find $(classpath-src) -name '*.java')
@ -1346,7 +1386,7 @@ $(generated-code): %.cpp: $(src)/types.def $(generator) $(classpath-dep)
$(classpath-build)/%.class: $(classpath-src)/%.java
@echo $(<)
$(classpath-dep): $(classpath-sources)
$(classpath-dep): $(classpath-sources) $(classpath-jar-dep)
@echo "compiling classpath classes"
@mkdir -p $(classpath-build)
$(javac) -d $(classpath-build) -bootclasspath $(boot-classpath) \
@ -1354,6 +1394,28 @@ $(classpath-dep): $(classpath-sources)
$(classpath-classes))
@touch $(@)
$(build)/%.o: $(luni-native)/%.cpp $(build)/android.dep
@echo "compiling $(@)"
@mkdir -p $(dir $(@))
$(cxx) $(android-cflags) -c $$($(windows-path) $(<)) $(call output,$(@))
$(build)/android.dep: $(luni-javas) $(dalvik-javas) $(xml-javas)
@echo "compiling luni classes"
@mkdir -p $(classpath-build)
@mkdir -p $(build)/android
@mkdir -p $(build)/android-src/external/fdlibm
@mkdir -p $(build)/android-src/libexpat
cp $(android)/fdlibm/fdlibm.h $(build)/android-src/external/fdlibm/
cp $(android)/expat/lib/expat.h $(build)/android-src/libexpat/
cp -a $(luni-java)/* $(dalvik-java)/* $(xml-java)/* $(build)/android-src/
sed -i 's/return ordinal - o.ordinal;/return ordinal - o.ordinal();/' \
$(build)/android-src/java/lang/Enum.java
find $(build)/android-src -name '*.java' > $(build)/android.txt
$(javac) -Xmaxerrs 1000 -d $(build)/android -sourcepath $(luni-java) \
@$(build)/android.txt
cp -r $(build)/android/* $(classpath-build)
@touch $(@)
$(test-build)/%.class: $(test)/%.java
@echo $(<)
@ -1568,7 +1630,7 @@ else
endif
$(bootimage-object) $(codeimage-object): $(bootimage-generator) \
$(openjdk-jar-dep)
$(classpath-jar-dep)
@echo "generating bootimage and codeimage binaries from $(classpath-build) using $(<)"
$(<) -cp $(classpath-build) -bootimage $(bootimage-object) -codeimage $(codeimage-object) \
-bootimage-symbols $(bootimage-symbols) \

172
src/classpath-android.cpp Normal file
View File

@ -0,0 +1,172 @@
/* Copyright (c) 2010-2012, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
#include "machine.h"
#include "classpath-common.h"
#include "process.h"
#include "util/runtime-array.h"
using namespace vm;
namespace {
namespace local {
class MyClasspath : public Classpath {
public:
MyClasspath(Allocator* allocator):
allocator(allocator)
{ }
virtual object
makeJclass(Thread* t, object class_)
{
PROTECT(t, class_);
object c = allocate(t, FixedSizeOfJclass, true);
setObjectClass(t, c, type(t, Machine::JclassType));
set(t, c, JclassVmClass, class_);
return c;
}
virtual object
makeString(Thread* t, object array, int32_t offset, int32_t length)
{
if (objectClass(t, array) == type(t, Machine::ByteArrayType)) {
PROTECT(t, array);
object charArray = makeCharArray(t, length);
for (int i = 0; i < length; ++i) {
expect(t, (byteArrayBody(t, array, offset + i) & 0x80) == 0);
charArrayBody(t, charArray, i) = byteArrayBody(t, array, offset + i);
}
array = charArray;
} else {
expect(t, objectClass(t, array) == type(t, Machine::CharArrayType));
}
return vm::makeString(t, array, offset, length, 0);
}
virtual object
makeThread(Thread* t, Thread* parent)
{
const unsigned MaxPriority = 10;
const unsigned NormalPriority = 5;
object group;
if (parent) {
group = threadGroup(t, parent->javaThread);
} else {
group = allocate(t, FixedSizeOfThreadGroup, true);
setObjectClass(t, group, type(t, Machine::ThreadGroupType));
threadGroupMaxPriority(t, group) = MaxPriority;
}
PROTECT(t, group);
object thread = allocate(t, FixedSizeOfThread, true);
setObjectClass(t, thread, type(t, Machine::ThreadType));
threadPriority(t, thread) = NormalPriority;
threadGroup(t, thread) = group;
return thread;
}
virtual object
makeJMethod(Thread* t, object)
{
abort(t); // todo
}
virtual object
getVMMethod(Thread* t, object)
{
abort(t); // todo
}
virtual object
makeJField(Thread* t, object)
{
abort(t); // todo
}
virtual object
getVMField(Thread* t, object)
{
abort(t); // todo
}
virtual void
clearInterrupted(Thread*)
{
// ignore
}
virtual void
runThread(Thread* t)
{
object method = resolveMethod
(t, root(t, Machine::BootLoader), "java/lang/Thread", "run",
"(Ljava/lang/Thread;)V");
t->m->processor->invoke(t, method, 0, t->javaThread);
}
virtual void
resolveNative(Thread* t, object method)
{
vm::resolveNative(t, method);
}
virtual void
boot(Thread*)
{
// ignore
}
virtual const char*
bootClasspath()
{
return AVIAN_CLASSPATH;
}
virtual void
updatePackageMap(Thread*, object)
{
// ignore
}
virtual void
dispose()
{
allocator->free(this, sizeof(*this));
}
Allocator* allocator;
};
} // namespace local
} // namespace
namespace vm {
Classpath*
makeClasspath(System*, Allocator* allocator, const char*, const char*)
{
return new (allocator->allocate(sizeof(local::MyClasspath)))
local::MyClasspath(allocator);
}
} // namespace vm

View File

@ -188,7 +188,8 @@
(require object interruptLock)
(require uint8_t interrupted)
(require uint8_t unparked)
(alias peer uint64_t eetop))
(alias peer uint64_t eetop)
(require uint64_t peer))
(type threadGroup java/lang/ThreadGroup)
@ -196,7 +197,8 @@
(type throwable java/lang/Throwable
(alias message object detailMessage)
(alias trace object backtrace))
(alias trace object backtrace)
(alias trace object stackState))
(type exception java/lang/Exception)
@ -286,7 +288,9 @@
(alias target object referent)
(alias queue object queue)
(alias jNext object next)
(alias jNext object queueNext)
(alias vmNext object discovered)
(alias vmNext object pendingNext)
(nogc object target)
(nogc object queue)
(nogc object vmNext))