From fa8ba2afc859a764ef38c79a5c5ccaafdb532510 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Mon, 11 Jun 2012 23:30:22 +0000 Subject: [PATCH] fix build for recent versions of OpenJDK 7 As of the latest code from the jdk7u-dev Mercurial repository, java.lang.String no longer has offset or length fields. Instead, the content fits exactly into the backing char array, so offset is implicitly zero and length is the length of the array. The VM previously relied on those fields being present, whereas this commit handles the case where they are not. In addition, I've made some changes to openjdk-src.mk to ensure that we can build against both a stock OpenJDK 7 and an IcedTea-patched version. --- openjdk-src.mk | 15 +++++++-------- src/classpath-openjdk.cpp | 16 ++++++++-------- src/machine.h | 33 +++++++++++++++++++++++++++++++++ src/type-generator.cpp | 5 +++++ 4 files changed, 53 insertions(+), 16 deletions(-) diff --git a/openjdk-src.mk b/openjdk-src.mk index 027b6a79b5..fbbce2e5e8 100644 --- a/openjdk-src.mk +++ b/openjdk-src.mk @@ -239,8 +239,7 @@ ifeq ($(platform),windows) -Ds6_bytes=_s6_bytes else openjdk-sources += \ - $(openjdk-src)/solaris/native/common/jdk_util_md.c \ - $(openjdk-src)/solaris/native/common/jni_util_md.c \ + $(shell find $(openjdk-src)/solaris/native/common -name '*.c') \ $(openjdk-src)/solaris/native/java/io/canonicalize_md.c \ $(openjdk-src)/solaris/native/java/io/Console_md.c \ $(openjdk-src)/solaris/native/java/io/FileDescriptor_md.c \ @@ -305,9 +304,6 @@ else ifeq ($(platform),linux) openjdk-sources += \ $(openjdk-src)/solaris/native/java/net/linux_close.c \ - $(openjdk-src)/solaris/native/common/deps/syscalls_fp.c \ - $(openjdk-src)/solaris/native/common/deps/gconf2/gconf_fp.c \ - $(openjdk-src)/solaris/native/common/deps/glib2/gio_fp.c \ $(openjdk-src)/solaris/native/sun/nio/ch/EPollArrayWrapper.c openjdk-headers-classes += \ @@ -316,6 +312,8 @@ else openjdk-cflags += \ "-I$(openjdk-src)/solaris/native/common/deps/glib2" \ "-I$(openjdk-src)/solaris/native/common/deps/gconf2" \ + "-I$(openjdk-src)/solaris/native/common/deps/fontconfig2" \ + "-I$(openjdk-src)/solaris/native/common/deps/gtk2" \ $(shell pkg-config --cflags glib-2.0) \ $(shell pkg-config --cflags gconf-2.0) endif @@ -341,12 +339,13 @@ openjdk-local-sources += \ $(src)/openjdk/my_net_util.c \ $(src)/openjdk/my_management.c -c-objects = $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%-openjdk.o,$(x))) +openjdk-c-objects = \ + $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%-openjdk.o,$(x))) openjdk-objects = \ - $(call c-objects,$(openjdk-sources),$(openjdk-src),$(build)/openjdk) + $(call openjdk-c-objects,$(openjdk-sources),$(openjdk-src),$(build)/openjdk) openjdk-local-objects = \ - $(call c-objects,$(openjdk-local-sources),$(src)/openjdk,$(build)/openjdk) + $(call openjdk-c-objects,$(openjdk-local-sources),$(src)/openjdk,$(build)/openjdk) openjdk-headers-dep = $(build)/openjdk/headers.dep diff --git a/src/classpath-openjdk.cpp b/src/classpath-openjdk.cpp index fe9dbfdbfb..e05a71260e 100644 --- a/src/classpath-openjdk.cpp +++ b/src/classpath-openjdk.cpp @@ -562,6 +562,14 @@ class MyClasspath : public Classpath { expect(t, loadLibrary(t, libraryPath, "java", true, true)); #endif // not AVIAN_OPENJDK_SRC + { object assertionLock = resolveField + (t, type(t, Machine::ClassLoaderType), "assertionLock", + "Ljava/lang/Object;"); + + set(t, root(t, Machine::BootLoader), fieldOffset(t, assertionLock), + root(t, Machine::BootLoader)); + } + { object class_ = resolveClass (t, root(t, Machine::BootLoader), "java/util/Properties", true, Machine::NoClassDefFoundErrorType); @@ -594,14 +602,6 @@ class MyClasspath : public Classpath { root(t, Machine::BootLoader)); } - { object assertionLock = resolveField - (t, type(t, Machine::ClassLoaderType), "assertionLock", - "Ljava/lang/Object;"); - - set(t, root(t, Machine::BootLoader), fieldOffset(t, assertionLock), - root(t, Machine::BootLoader)); - } - { object scl = resolveField (t, type(t, Machine::ClassLoaderType), "scl", "Ljava/lang/ClassLoader;"); diff --git a/src/machine.h b/src/machine.h index bb3b97a43c..9671d6cf7c 100644 --- a/src/machine.h +++ b/src/machine.h @@ -2233,6 +2233,39 @@ makeByteArray(Thread* t, const char* format, ...); object makeString(Thread* t, const char* format, ...); +#ifndef HAVE_StringOffset + +inline unsigned +stringLength(Thread* t, object string) +{ + return arrayLength(t, stringData(t, string)); +} + +inline unsigned +stringOffset(Thread*, object) +{ + return 0; +} + +inline object +makeString(Thread* t, object data, unsigned offset, unsigned length, unsigned) +{ + if (offset == 0 and length == arrayLength(t, data)) { + return makeString(t, data, 0, 0); + } else { + PROTECT(t, data); + + object array = makeCharArray(t, length); + + memcpy(&charArrayBody(t, array, 0), &charArrayBody(t, data, offset), + length * 2); + + return makeString(t, array, 0, 0); + } +} + +#endif // not HAVE_StringOffset + int stringUTFLength(Thread* t, object string, unsigned start, unsigned length); diff --git a/src/type-generator.cpp b/src/type-generator.cpp index 813cce7dcd..f31b0f18c8 100644 --- a/src/type-generator.cpp +++ b/src/type-generator.cpp @@ -1384,6 +1384,11 @@ writeAccessor(Output* out, Object* member, Object* offset, bool unsafe = false) out->write(" = "); writeOffset(out, offset); out->write(";\n\n"); + + out->write("#define HAVE_"); + out->write(capitalize(local::typeName(memberOwner(member)))); + out->write(capitalize(memberName(member))); + out->write(" 1\n\n"); } out->write("inline ");