From 940b4d1848e8c70ab7642901a68594e8016caffc Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 27 Apr 2024 18:51:28 +0200 Subject: Adding upstream version 1:7.0.4. Signed-off-by: Daniel Baumann --- jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx | 158 +++ .../plugins/sunmajor/pluginlib/JREProperties.java | 62 + jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h | 35 + jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx | 281 +++++ jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx | 50 + jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx | 115 ++ jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx | 45 + .../plugins/sunmajor/pluginlib/sunjavaplugin.cxx | 895 ++++++++++++++ jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx | 118 ++ jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx | 44 + jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx | 417 +++++++ jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx | 115 ++ jvmfwk/plugins/sunmajor/pluginlib/util.cxx | 1278 ++++++++++++++++++++ jvmfwk/plugins/sunmajor/pluginlib/util.hxx | 116 ++ jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx | 14 + jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm | 133 ++ jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx | 196 +++ jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx | 55 + jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx | 49 + 19 files changed, 4176 insertions(+) create mode 100644 jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunjre.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunjre.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/sunversion.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.hxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/util_cocoa.mm create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/vendorbase.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/vendorlist.cxx create mode 100644 jvmfwk/plugins/sunmajor/pluginlib/vendorlist.hxx (limited to 'jvmfwk/plugins') diff --git a/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx new file mode 100644 index 000000000..f7c295ec1 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/javaenvsetup/javaldx.cxx @@ -0,0 +1,158 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +static bool hasOption(char const * szOption, int argc, char** argv); +static OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData); +static bool findAndSelect(std::unique_ptr*); + +#define HELP_TEXT \ +"\njavaldx is necessary to make Java work on some UNIX platforms." \ +"It prints a string to std out that consists of directories which " \ +"have to be included into the LD_LIBRARY_PATH variable.The setting of " \ +"the variable usually occurs in a shell script that runs javaldx.\n" \ +"The directories are from the chosen java installation. \n" \ +"Options are: \n"\ +"--help or -h\n" + +SAL_IMPLEMENT_MAIN_WITH_ARGS(argc, argv) +{ + try + { + if( hasOption("--help",argc, argv) || hasOption("-h", argc, argv)) + { + fprintf(stdout, HELP_TEXT);// default + return 0; + } + bool bEnabled = false; + javaFrameworkError errcode = jfw_getEnabled( & bEnabled); + if (errcode == JFW_E_NONE && !bEnabled) + { + //Do not do any preparation because that may only slow startup time. + return 0; + } + else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE) + { + fprintf(stderr,"javaldx failed!\n"); + return -1; + } + + std::unique_ptr aInfo; + errcode = jfw_getSelectedJRE(&aInfo); + + if (errcode != JFW_E_NONE && errcode != JFW_E_INVALID_SETTINGS) + { + fprintf(stderr,"javaldx failed!\n"); + return -1; + } + + if (!aInfo) + { + if (!findAndSelect(&aInfo)) + return -1; + } + else + { + //check if the JRE was not uninstalled + bool bExist = false; + errcode = jfw_existJRE(aInfo.get(), &bExist); + if (errcode == JFW_E_NONE) + { + if (!bExist && !findAndSelect(&aInfo)) + return -1; + } + else + { + fprintf(stderr, "javaldx: Could not determine if JRE still exist\n"); + return -1; + } + } + + OString sPaths = getLD_LIBRARY_PATH(aInfo->arVendorData); + fprintf(stdout, "%s\n", sPaths.getStr()); + } + catch (const std::exception& e) + { + std::cerr << "javaldx failed! " << e.what() << std::endl; + return -1; + } + + return 0; +} + +OString getLD_LIBRARY_PATH(const rtl::ByteSequence & vendorData) +{ + const sal_Unicode* chars = reinterpret_cast(vendorData.getConstArray()); + sal_Int32 len = vendorData.getLength(); + OUString sData(chars, len / 2); + //the runtime lib is on the first line + sal_Int32 index = 0; + OUString aToken = sData.getToken( 1, '\n', index); + + OString paths = + OUStringToOString(aToken, osl_getThreadTextEncoding()); + return paths; +} + +static bool hasOption(char const * szOption, int argc, char** argv) +{ + bool retVal= false; + for(int i= 1; i < argc; i++) + { + if( ! strcmp(argv[i], szOption)) + { + retVal= true; + break; + } + } + return retVal; +} + +static bool findAndSelect(std::unique_ptr * ppInfo) +{ + javaFrameworkError errcode = jfw_findAndSelectJRE(ppInfo); + if (errcode == JFW_E_NO_JAVA_FOUND) + { + fprintf(stderr,"javaldx: Could not find a Java Runtime Environment!\n"); + return false; + } + else if (errcode != JFW_E_NONE && errcode != JFW_E_DIRECT_MODE) + { + fprintf(stderr,"javaldx failed!\n"); + return false; + } + return true; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java b/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java new file mode 100644 index 000000000..0d3503af3 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/JREProperties.java @@ -0,0 +1,62 @@ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +import java.util.*; + +/** This class prints out the system properties. + + We cannot print the strings directly because of encoding issues. Since + about 1.3.1 one can start java with the option -Dfile.encoding=UTF-8, but + unfortunately this works only with later update - versions (for example, + 1.3.1_07). Therefore we use this scheme. The property string has this form: + name=value + + Every character is cast to an integer which value is printed, followed by a + space. If all characters of the string are printed, then a new line is printed. +*/ +public class JREProperties +{ + public static void main(String[] args) + { + try + { + Properties p = System.getProperties(); + Enumeration e = p.propertyNames(); + while (e.hasMoreElements()) { + String sProp = (String) e.nextElement(); + String sCompleteProp = sProp + "=" + p.getProperty(sProp); + char[] arChars = new char[sCompleteProp.length()]; + sCompleteProp.getChars(0, sCompleteProp.length(), arChars, 0); + for (int c = 0; c < arChars.length; c++) { + System.out.print(String.valueOf((int) arChars[c])); + System.out.print(" "); + } + System.out.print("\n"); + } + } + catch(Exception e) + { + System.err.println(e); + } + + System.exit(0); + } + + + +} diff --git a/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h new file mode 100644 index 000000000..599c40438 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/diagnostics.h @@ -0,0 +1,35 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_DIAGNOSTICS_H +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_DIAGNOSTICS_H + +#include + +#include + +#define JFW_ENSURE(c, m) SAL_WARN_IF(!(c), "jfw", m) + +#define JFW_TRACE0(m) SAL_INFO("jfw.level1", m) + +#define JFW_TRACE2(m) SAL_INFO("jfw.level2", m) + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx new file mode 100644 index 000000000..19cc9bf5d --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.cxx @@ -0,0 +1,281 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include +#include "gnujre.hxx" +#include "util.hxx" + +using namespace std; +using namespace osl; +using ::rtl::Reference; + +namespace jfw_plugin +{ + +Reference GnuInfo::createInstance() +{ + return new GnuInfo; +} + +char const* const* GnuInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { + "gij", + "bin/gij", + "gij-4.3", + "bin/gij-4.3", + "gij-4.2", + "bin/gij-4.2", + "gij-4.1", + "bin/gij-4.1" + }; + *size = SAL_N_ELEMENTS (ar); + return ar; +} + +#if defined(MIPS) && defined(OSL_LITENDIAN) +#define GCJ_JFW_PLUGIN_ARCH "mipsel" +#elif defined(MIPS64) && defined(OSL_LITENDIAN) +#define GCJ_JFW_PLUGIN_ARCH "mips64el" +#else +#define GCJ_JFW_PLUGIN_ARCH JFW_PLUGIN_ARCH +#endif + +char const* const* GnuInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { + "/libjvm.so", + "/lib/" GCJ_JFW_PLUGIN_ARCH "/client/libjvm.so", + "/gcj-4.1.1/libjvm.so", + "/gcj-4.3-90/libjvm.so", + "/gcj-4.2-81/libjvm.so", + "/gcj-4.2/libjvm.so", + "/gcj-4.2.1/libjvm.so", + "/gcj-4.2.2/libjvm.so", + "/gcj-4.2.3/libjvm.so", + "/gcj-4.1-71/libjvm.so", + "/gcj-4_1/libjvm.so", + "/gcj-4.1/libjvm.so", + "/libgcj.so.81", + "/libgcj.so.80", + "/libgcj.so.8", + "/libgcj.so.71", + "/libgcj.so.70", + "/libgcj.so.7", + "/libgcj.so.6" + }; + *size = SAL_N_ELEMENTS(ar); + return ar; +} + +char const* const* GnuInfo::getLibraryPaths(int* /*size*/) +{ + return nullptr; +} + +bool GnuInfo::initialize(vector > props) +{ + //get java.vendor, java.version, java.home + //from system properties + + OUString sJavaLibraryPath; + OUString const sVendorProperty("java.vendor"); + OUString const sVersionProperty("java.version"); + OUString const sJavaHomeProperty("java.home"); + OUString const sJavaLibraryPathProperty("java.library.path"); + OUString const sGNUHomeProperty("gnu.classpath.home.url"); + + bool bVersion = false; + bool bVendor = false; + bool bHome = false; + bool bJavaHome = false; + bool bJavaLibraryPath = false; + + for (auto const& prop : props) + { + if(! bVendor && sVendorProperty == prop.first) + { + m_sVendor = prop.second; + bVendor = true; + } + else if (!bVersion && sVersionProperty == prop.first) + { + m_sVersion = prop.second; + bVersion = true; + } + else if (!bHome && sGNUHomeProperty == prop.first) + { + m_sHome = prop.second; + bHome = true; + } + else if (!bJavaHome && sJavaHomeProperty == prop.first) + { + OUString fileURL; + if (osl_getFileURLFromSystemPath(prop.second.pData,& fileURL.pData) == + osl_File_E_None) + { + //make sure that the drive letter have all the same case + //otherwise file:///c:/jre and file:///C:/jre produce two + //different objects!!! + if (makeDriveLetterSame( & fileURL)) + { + m_sJavaHome = fileURL; + bJavaHome = true; + } + } + } + else if (!bJavaLibraryPath && sJavaLibraryPathProperty == prop.first) + { + sal_Int32 nIndex = 0; + osl_getFileURLFromSystemPath(prop.second.getToken(0, ':', nIndex).pData, &sJavaLibraryPath.pData); + bJavaLibraryPath = true; + } + if (bVendor && bVersion && bHome && bJavaHome && bJavaLibraryPath) { + break; + } + } + if (!bVersion || !bVendor || !bHome) + return false; + + if (m_sJavaHome.isEmpty()) + m_sJavaHome = "file:///usr/lib"; + + // init m_sRuntimeLibrary + OSL_ASSERT(!m_sHome.isEmpty()); + //call virtual function to get the possible paths to the runtime library. + + int size = 0; + char const* const* arRtPaths = getRuntimePaths( & size); + vector libpaths = getVectorFromCharArray(arRtPaths, size); + + bool bRt = false; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + + if (!bRt) + { + m_sHome = m_sJavaHome; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } + + // try to find it by the java.library.path property + if (!bRt && m_sJavaHome != sJavaLibraryPath) + { + m_sHome = sJavaLibraryPath; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } + +#ifdef X86_64 + //Make one last final legacy attempt on x86_64 in case the distro placed it in lib64 instead + if (!bRt && m_sJavaHome != "file:///usr/lib") + { + m_sHome = "file:///usr/lib64"; + for (auto const& libpath : libpaths) + { + //Construct an absolute path to the possible runtime + OUString usRt= m_sHome + libpath; + DirectoryItem item; + if(DirectoryItem::get(usRt, item) == File::E_None) + { + //found runtime lib + m_sRuntimeLibrary = usRt; + bRt = true; + break; + } + } + } +#endif + + if (!bRt) + return false; + + // init m_sLD_LIBRARY_PATH + OSL_ASSERT(!m_sHome.isEmpty()); + size = 0; + char const * const * arLDPaths = getLibraryPaths( & size); + vector ld_paths = getVectorFromCharArray(arLDPaths, size); + + bool bLdPath = true; + int c = 0; + for (auto const& ld_path : ld_paths) + { + OUString usAbsUrl= m_sHome + ld_path; + // convert to system path + OUString usSysPath; + if(File::getSystemPathFromFileURL(usAbsUrl, usSysPath) == File::E_None) + { + + if(c > 0) + m_sLD_LIBRARY_PATH+= OUStringChar(SAL_PATHSEPARATOR); + m_sLD_LIBRARY_PATH+= usSysPath; + } + else + { + bLdPath = false; + break; + } + ++c; + } + return bLdPath; +} + +int GnuInfo::compareVersions(const OUString&) const +{ + return 0; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx new file mode 100644 index 000000000..4826ea720 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/gnujre.hxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_GNUJRE_HXX +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_GNUJRE_HXX + +#include + +namespace jfw_plugin +{ + +class GnuInfo: public VendorBase +{ +private: + OUString m_sJavaHome; +public: + static char const* const* getJavaExePaths(int * size); + + static rtl::Reference createInstance(); + + virtual char const* const* getRuntimePaths(int * size) override; + + virtual char const* const* getLibraryPaths(int* size) override; + + virtual bool initialize( + std::vector > props) override; + virtual int compareVersions(const OUString& sSecond) const override; + +}; + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx new file mode 100644 index 000000000..8a10d39a8 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.cxx @@ -0,0 +1,115 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "otherjre.hxx" + +using namespace std; + +using ::rtl::Reference; +namespace jfw_plugin +{ + +Reference OtherInfo::createInstance() +{ + return new OtherInfo; +} + + +char const* const* OtherInfo::getJavaExePaths(int * size) +{ + static char const * ar[] = { +#if defined(_WIN32) + "bin/java.exe", + "jre/bin/java.exe" +#elif defined UNX + "bin/java", + "jre/bin/java" +#endif + }; + *size = SAL_N_ELEMENTS (ar); + return ar; +} + +char const* const* OtherInfo::getRuntimePaths(int * size) +{ + static char const* ar[]= { +#if defined(_WIN32) + "/bin/client/jvm.dll", + "/bin/hotspot/jvm.dll", + "/bin/classic/jvm.dll", + "/bin/jrockit/jvm.dll", + "/bin/server/jvm.dll" // needed by Azul +#elif defined UNX +#ifdef MACOSX + "/../../../../../Frameworks/JavaVM.framework/JavaVM", //as of 1.6.0_22 + "/lib/server/libjvm.dylib" // needed by Azul +#else + "/lib/" JFW_PLUGIN_ARCH "/client/libjvm.so", // for Blackdown PPC + "/lib/" JFW_PLUGIN_ARCH "/server/libjvm.so", // for Blackdown AMD64 + "/lib/" JFW_PLUGIN_ARCH "/classic/libjvm.so", // for Blackdown PPC + "/lib/" JFW_PLUGIN_ARCH "/jrockit/libjvm.so", // for Java of BEA Systems + "/bin/classic/libjvm.so", // fallback for older for IBM Java + "/jre/bin/classic/libjvm.so" // fallback for older for IBM Java +#endif +#endif + + }; + *size = SAL_N_ELEMENTS(ar); + return ar; +} + +char const* const* OtherInfo::getLibraryPaths(int* size) +{ + +#if defined(UNX) && !defined(MACOSX) + //mac version does not have a ld library path anymore + static char const * ar[] = { + "/bin", + "/jre/bin", + "/bin/classic", + "/jre/bin/classic", + "/lib/" JFW_PLUGIN_ARCH "/client", + "/lib/" JFW_PLUGIN_ARCH "/server", + "/lib/" JFW_PLUGIN_ARCH "/classic", + "/lib/" JFW_PLUGIN_ARCH "/jrockit", + "/lib/" JFW_PLUGIN_ARCH "/native_threads", + "/lib/" JFW_PLUGIN_ARCH + }; + + *size = SAL_N_ELEMENTS(ar); + return ar; +#else + *size = 0; + return nullptr; +#endif +} + +int OtherInfo::compareVersions(const OUString& /*sSecond*/) const +{ + //Need to provide an own algorithm for comparing version. + //Because this function returns always 0, which means the version of + //this JRE and the provided version "sSecond" are equal, one cannot put + //any excludeVersion entries in the javavendors.xml file. + return 0; +} + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx new file mode 100644 index 000000000..57b3a5e39 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/otherjre.hxx @@ -0,0 +1,45 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_OTHERJRE_HXX +#define INCLUDED_JVMFWK_PLUGINS_SUNMAJOR_PLUGINLIB_OTHERJRE_HXX + +#include + +namespace jfw_plugin +{ +/* Do not forget to put this class in the vendor map in vendorlist.cxx + */ +class OtherInfo: public VendorBase +{ +public: + static char const* const* getJavaExePaths(int * size); + + static rtl::Reference createInstance(); + + virtual char const* const* getRuntimePaths(int * size) override; + virtual char const* const* getLibraryPaths(int* size) override; + virtual int compareVersions(const OUString& sSecond) const override; + +}; + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx new file mode 100644 index 000000000..abe47b567 --- /dev/null +++ b/jvmfwk/plugins/sunmajor/pluginlib/sunjavaplugin.cxx @@ -0,0 +1,895 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#ifdef _WIN32 +# include +# include +# if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# include +#endif + +#ifdef ANDROID +# include +#endif + +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include "util.hxx" +#include "sunversion.hxx" +#include "diagnostics.h" + +#ifdef MACOSX +#include "util_cocoa.hxx" +#endif + +#ifdef ANDROID +#include +#else +#if !ENABLE_RUNTIME_OPTIMIZATIONS +#define FORCE_INTERPRETED 1 +#elif defined HAVE_VALGRIND_HEADERS +#include +#define FORCE_INTERPRETED RUNNING_ON_VALGRIND +#else +#define FORCE_INTERPRETED 0 +#endif +#endif + +#if defined LINUX && (defined X86 || defined X86_64) +#include +#endif + +using namespace osl; +using namespace std; +using namespace jfw_plugin; + + +namespace { + +struct PluginMutex: public ::rtl::Static {}; + +#if defined(UNX) && !defined(ANDROID) +OString getPluginJarPath( + const OUString & sVendor, + const OUString& sLocation, + const OUString& sVersion) +{ + OString ret; + OUString sName1("javaplugin.jar"); + OUString sName2("plugin.jar"); + OUString sPath; + if ( sVendor == "Sun Microsystems Inc." ) + { + SunVersion ver142("1.4.2-ea"); + SunVersion ver150("1.5.0-ea"); + SunVersion ver(sVersion); + OSL_ASSERT(ver142 && ver150 && ver); + + OUString sName; + if (ver < ver142) + { + sName = sName1; + } + else if (ver < ver150) + {//this will cause ea, beta etc. to have plugin.jar in path. + //but this does not harm. 1.5.0-beta < 1.5.0 + sName = sName2; + } + if (!sName.isEmpty()) + { + sName = sLocation + "/lib/" + sName; + OSL_VERIFY( + osl_getSystemPathFromFileURL(sName.pData, & sPath.pData) + == osl_File_E_None); + } + } + else + { + OUString sName(sLocation + "/lib/" + sName1); + OUString sPath1; + OUString sPath2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath1.pData) + == osl_File_E_None) + { + sName = sLocation + "/lib/" + sName2; + if (osl_getSystemPathFromFileURL(sName.pData, & sPath2.pData) + == osl_File_E_None) + { + sPath = sPath1 + OUStringChar(SAL_PATHSEPARATOR) + sPath2; + } + } + OSL_ASSERT(!sPath.isEmpty()); + } + ret = OUStringToOString(sPath, osl_getThreadTextEncoding()); + + return ret; +} +#endif // UNX + + +std::unique_ptr createJavaInfo( + const rtl::Reference & info) +{ + OUStringBuffer buf(1024); + buf.append(info->getRuntimeLibrary()); + if (!info->getLibraryPath().isEmpty()) + { + buf.append("\n"); + buf.append(info->getLibraryPath()); + buf.append("\n"); + } + OUString sVendorData = buf.makeStringAndClear(); + return std::unique_ptr( + new JavaInfo{ + info->getVendor(), info->getHome(), info->getVersion(), + sal_uInt64(info->needsRestart() ? JFW_REQUIRE_NEEDRESTART : 0), + rtl::ByteSequence( + reinterpret_cast(sVendorData.pData->buffer), + sVendorData.getLength() * sizeof(sal_Unicode))}); +} + +OUString getRuntimeLib(const rtl::ByteSequence & data) +{ + const sal_Unicode* chars = reinterpret_cast(data.getConstArray()); + sal_Int32 len = data.getLength(); + OUString sData(chars, len / 2); + //the runtime lib is on the first line + sal_Int32 index = 0; + OUString aToken = sData.getToken( 0, '\n', index); + + return aToken; +} + +jmp_buf jmp_jvm_abort; +sig_atomic_t g_bInGetJavaVM = 0; + +extern "C" void JNICALL abort_handler() +{ + // If we are within JNI_CreateJavaVM then we jump back into getJavaVM + if( g_bInGetJavaVM != 0 ) + { + fprintf(stderr, "JavaVM: JNI_CreateJavaVM called os::abort(), caught by abort_handler in javavm.cxx\n"); + longjmp( jmp_jvm_abort, 0); + } +} + +typedef jint JNICALL JNI_CreateVM_Type(JavaVM **, JNIEnv **, void *); + +#ifndef ANDROID +int createJvm( + JNI_CreateVM_Type * pCreateJavaVM, JavaVM ** pJavaVM, JNIEnv ** ppEnv, JavaVMInitArgs * vm_args) +{ + /* We set a global flag which is used by the abort handler in order to + determine whether it is should use longjmp to get back into this function. + That is, the abort handler determines if it is on the same stack as this function + and then jumps back into this function. + */ + g_bInGetJavaVM = 1; + jint err; + memset( jmp_jvm_abort, 0, sizeof(jmp_jvm_abort)); + /* If the setjmp return value is not "0" then this point was reached by a longjmp in the + abort_handler, which was called indirectly by JNI_CreateVM. + */ + if( setjmp( jmp_jvm_abort ) == 0) + { + //returns negative number on failure + err= pCreateJavaVM(pJavaVM, ppEnv, vm_args); + g_bInGetJavaVM = 0; + } + else + // set err to a positive number, so as or recognize that an abort (longjmp) + //occurred + err= 1; + return err; +} +#endif + +/** helper function to check Java version requirements + + This function checks if the Java version of the given VendorBase + meets the given Java version requirements. + + @param aVendorInfo + [in] the object to be inspected whether it meets the version requirements + @param sMinVersion + [in] represents the minimum version of a JRE. The string can be empty. + @param sMaxVersion + [in] represents the maximum version of a JRE. The string can be empty. + @param arExcludeList + [in] contains a list of "bad" versions. JREs which have one of these + versions must not be returned by this function. + + @return + javaPluginError::NONE the function ran successfully and the version requirements are met + javaPluginError::FailedVersion at least one of the version requirements (minVersion, + maxVersion, excludeVersions) was violated + javaPluginError::WrongVersionFormat the version strings in + sMinVersion,sMaxVersion,arExcludeList are not recognized as valid + version strings. + + */ +javaPluginError checkJavaVersionRequirements( + rtl::Reference const & aVendorInfo, + OUString const& sMinVersion, + OUString const& sMaxVersion, + std::vector const & arExcludeList) +{ + if (!aVendorInfo->isValidArch()) + { + return javaPluginError::WrongArch; + } + if (!sMinVersion.isEmpty()) + { + try + { + if (aVendorInfo->compareVersions(sMinVersion) < 0) + return javaPluginError::FailedVersion; + } + catch (MalformedVersionException&) + { + //The minVersion was not recognized as valid for this vendor. + JFW_ENSURE( + false, + "[Java framework]sunjavaplugin does not know version: " + + sMinVersion + " for vendor: " + aVendorInfo->getVendor() + + " .Check minimum Version." ); + return javaPluginError::WrongVersionFormat; + } + } + + if (!sMaxVersion.isEmpty()) + { + try + { + if (aVendorInfo->compareVersions(sMaxVersion) > 0) + return javaPluginError::FailedVersion; + } + catch (MalformedVersionException&) + { + //The maxVersion was not recognized as valid for this vendor. + JFW_ENSURE( + false, + "[Java framework]sunjavaplugin does not know version: " + + sMaxVersion + " for vendor: " + aVendorInfo->getVendor() + + " .Check maximum Version." ); + return javaPluginError::WrongVersionFormat; + } + } + + for (auto const & sExVer: arExcludeList) { + try + { + if (aVendorInfo->compareVersions(sExVer) == 0) + return javaPluginError::FailedVersion; + } + catch (MalformedVersionException&) + { + //The excluded version was not recognized as valid for this vendor. + JFW_ENSURE( + false, + "[Java framework]sunjavaplugin does not know version: " + + sExVer + " for vendor: " + aVendorInfo->getVendor() + + " .Check excluded versions." ); + return javaPluginError::WrongVersionFormat; + } + } + + return javaPluginError::NONE; +} + +} + +javaPluginError jfw_plugin_getAllJavaInfos( + bool checkJavaHomeAndPath, + jfw::VendorSettings const & vendorSettings, + std::vector>* parJavaInfo, + std::vector> & infos) +{ + assert(parJavaInfo); + + //Find all JREs + vector > vecInfos = + addAllJREInfos(checkJavaHomeAndPath, infos); + vector > vecVerifiedInfos; + + for (auto const& vecInfo : vecInfos) + { + if (auto const versionInfo = vendorSettings.getVersionInformation(vecInfo->getVendor())) + { + javaPluginError err = checkJavaVersionRequirements( + vecInfo, versionInfo->sMinVersion, versionInfo->sMaxVersion, versionInfo->vecExcludeVersions); + + if (err == javaPluginError::FailedVersion || err == javaPluginError::WrongArch) + continue; + else if (err == javaPluginError::WrongVersionFormat) + return err; + } + + vecVerifiedInfos.push_back(vecInfo); + } + //Now vecVerifiedInfos contains all those JREs which meet the version requirements + //Transfer them into the array that is passed out. + parJavaInfo->clear(); + for (auto const& vecVerifiedInfo : vecVerifiedInfos) + { + parJavaInfo->push_back(createJavaInfo(vecVerifiedInfo)); + } + + return javaPluginError::NONE; +} + +javaPluginError jfw_plugin_getJavaInfoByPath( + OUString const& sPath, + jfw::VendorSettings const & vendorSettings, + std::unique_ptr * ppInfo) +{ + assert(ppInfo != nullptr); + OSL_ASSERT(!sPath.isEmpty()); + if (sPath.isEmpty()) + return javaPluginError::InvalidArg; + + rtl::Reference aVendorInfo = getJREInfoByPath(sPath); + if (!aVendorInfo.is()) + return javaPluginError::NoJre; + + //Check if the detected JRE matches the version requirements + javaPluginError errorcode = javaPluginError::NONE; + if (auto const versionInfo = vendorSettings.getVersionInformation(aVendorInfo->getVendor())) + { + errorcode = checkJavaVersionRequirements( + aVendorInfo, versionInfo->sMinVersion, versionInfo->sMaxVersion, versionInfo->vecExcludeVersions); + } + + if (errorcode == javaPluginError::NONE) + *ppInfo = createJavaInfo(aVendorInfo); + + return errorcode; +} + +javaPluginError jfw_plugin_getJavaInfoFromJavaHome( + jfw::VendorSettings const & vendorSettings, + std::unique_ptr * ppInfo, + std::vector> & infos) +{ + assert(ppInfo); + + std::vector> infoJavaHome; + addJavaInfoFromJavaHome(infos, infoJavaHome); + + if (infoJavaHome.empty()) + return javaPluginError::NoJre; + assert(infoJavaHome.size() == 1); + + //Check if the detected JRE matches the version requirements + auto const versionInfo = vendorSettings.getVersionInformation(infoJavaHome[0]->getVendor()); + if (!versionInfo + || (checkJavaVersionRequirements( + infoJavaHome[0], + versionInfo->sMinVersion, + versionInfo->sMaxVersion, + versionInfo->vecExcludeVersions) + == javaPluginError::NONE)) + { + *ppInfo = createJavaInfo(infoJavaHome[0]); + return javaPluginError::NONE; + } + + return javaPluginError::NoJre; +} + +javaPluginError jfw_plugin_getJavaInfosFromPath( + jfw::VendorSettings const & vendorSettings, + std::vector> & javaInfosFromPath, + std::vector> & infos) +{ + // find JREs from PATH + vector> vecInfosFromPath; + addJavaInfosFromPath(infos, vecInfosFromPath); + + vector> vecVerifiedInfos; + + // copy infos of JREs that meet version requirements to vecVerifiedInfos + for (auto const& infosFromPath : vecInfosFromPath) + { + auto const versionInfo = vendorSettings.getVersionInformation(infosFromPath->getVendor()); + if (!versionInfo + || (checkJavaVersionRequirements( + infosFromPath, + versionInfo->sMinVersion, + versionInfo->sMaxVersion, + versionInfo->vecExcludeVersions) + == javaPluginError::NONE)) + { + vecVerifiedInfos.push_back(createJavaInfo(infosFromPath)); + } + } + + if (vecVerifiedInfos.empty()) + return javaPluginError::NoJre; + + javaInfosFromPath = std::move(vecVerifiedInfos); + + return javaPluginError::NONE; +} + + +#if defined(_WIN32) + +// Load msvcr71.dll using an explicit full path from where it is +// present as bundled with the JRE. In case it is not found where we +// think it should be, do nothing, and just let the implicit loading +// that happens when loading the JVM take care of it. + +static void load_msvcr(OUString const & jvm_dll, OUStringLiteral msvcr) +{ + // First check if msvcr71.dll is in the same folder as jvm.dll. It + // normally isn't, at least up to 1.6.0_22, but who knows if it + // might be in the future. + sal_Int32 slash = jvm_dll.lastIndexOf('\\'); + + if (slash == -1) + { + // Huh, weird path to jvm.dll. Oh well. + SAL_WARN("jfw", "JVM pathname <" + jvm_dll + "> w/o backslash"); + return; + } + + if (LoadLibraryW( + o3tl::toW(OUString(jvm_dll.copy(0, slash+1) + msvcr).getStr()))) + return; + + // Then check if msvcr71.dll is in the parent folder of where + // jvm.dll is. That is currently (1.6.0_22) as far as I know the + // normal case. + slash = jvm_dll.lastIndexOf('\\', slash); + + if (slash == -1) + return; + + (void)LoadLibraryW( + o3tl::toW(OUString(jvm_dll.copy(0, slash+1) + msvcr).getStr())); +} + +// Check if the jvm DLL imports msvcr71.dll, and in that case try +// loading it explicitly. In case something goes wrong, do nothing, +// and just let the implicit loading try to take care of it. +static void do_msvcr_magic(OUString const &jvm_dll) +{ + struct stat st; + + OUString Module; + osl::FileBase::RC nError = osl::FileBase::getSystemPathFromFileURL( + jvm_dll, Module); + + if ( osl::FileBase::E_None != nError ) + { + SAL_WARN( + "jfw", "getSystemPathFromFileURL(" << jvm_dll << "): " << +nError); + return; + } + + FILE *f = _wfopen(o3tl::toW(Module.getStr()), L"rb"); + + if (!f) + { + SAL_WARN("jfw", "_wfopen(" << Module << ") failed"); + return; + } + + if (fstat(fileno(f), &st) == -1) + { + SAL_WARN("jfw", "fstat(" << Module << ") failed"); + fclose(f); + return; + } + + PIMAGE_DOS_HEADER dos_hdr = static_cast(malloc(st.st_size)); + assert(dos_hdr); + if (fread(dos_hdr, st.st_size, 1, f) != 1 || + memcmp(dos_hdr, "MZ", 2) != 0 || + dos_hdr->e_lfanew < 0 || + dos_hdr->e_lfanew > static_cast(st.st_size - sizeof(IMAGE_NT_HEADERS))) + { + SAL_WARN("jfw", "analyzing <" << Module << "> failed"); + free(dos_hdr); + fclose(f); + return; + } + + fclose(f); + + IMAGE_NT_HEADERS *nt_hdr = reinterpret_cast(reinterpret_cast(dos_hdr) + dos_hdr->e_lfanew); + + DWORD importsVA = nt_hdr->OptionalHeader + .DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress; + // first determine Virtual-to-File-address mapping for the section + // that contains the import directory + IMAGE_SECTION_HEADER *sections = IMAGE_FIRST_SECTION(nt_hdr); + ptrdiff_t VAtoPhys = -1; + for (int i = 0; i < nt_hdr->FileHeader.NumberOfSections; ++i) + { + if (sections->VirtualAddress <= importsVA && + importsVA < sections->VirtualAddress + sections->SizeOfRawData) + { + VAtoPhys = static_cast(sections->PointerToRawData) - static_cast(sections->VirtualAddress); + break; + } + ++sections; + } + if (-1 == VAtoPhys) // not found? + { + SAL_WARN("jfw", "analyzing <" << Module << "> failed"); + free(dos_hdr); + return; + } + IMAGE_IMPORT_DESCRIPTOR *imports = + reinterpret_cast(reinterpret_cast(dos_hdr) + importsVA + VAtoPhys); + + while (imports <= reinterpret_cast(reinterpret_cast(dos_hdr) + st.st_size - sizeof (IMAGE_IMPORT_DESCRIPTOR)) && + imports->Name != 0 && + imports->Name + VAtoPhys < static_cast(st.st_size)) + { + static OUStringLiteral msvcrts[] = + { + "msvcr71.dll", + "msvcr100.dll" + }; + char const* importName = reinterpret_cast(dos_hdr) + imports->Name + VAtoPhys; + sal_Int32 importNameLen = rtl_str_getLength(importName); + for (size_t i = 0; i < SAL_N_ELEMENTS(msvcrts); ++i) + { + if (0 == rtl_str_compareIgnoreAsciiCase_WithLength( + importName, importNameLen, + msvcrts[i].data, msvcrts[i].size)) + { + load_msvcr(Module, msvcrts[i]); + free(dos_hdr); + return; + } + } + imports++; + } + + free(dos_hdr); +} + +#endif + +/** starts a Java Virtual Machine. +

+ The function shall ensure, that the VM does not abort the process + during instantiation. +

+ */ +javaPluginError jfw_plugin_startJavaVirtualMachine( + const JavaInfo *pInfo, + const JavaVMOption* arOptions, + sal_Int32 cOptions, + JavaVM ** ppVm, + JNIEnv ** ppEnv) +{ + assert(pInfo != nullptr); + assert(ppVm != nullptr); + assert(ppEnv != nullptr); + osl::MutexGuard guard(PluginMutex::get()); + javaPluginError errorcode = javaPluginError::NONE; +#ifdef MACOSX + rtl::Reference aVendorInfo = getJREInfoByPath( pInfo->sLocation ); + if ( !aVendorInfo.is() || aVendorInfo->compareVersions( pInfo->sVersion ) < 0 ) + return javaPluginError::VmCreationFailed; +#endif + OUString sRuntimeLib = getRuntimeLib(pInfo->arVendorData); +#ifdef MACOSX + if ( !JvmfwkUtil_isLoadableJVM( sRuntimeLib ) ) + return javaPluginError::VmCreationFailed; +#endif + JFW_TRACE2("Using Java runtime library: " << sRuntimeLib); + +#ifndef ANDROID + // On linux we load jvm with RTLD_GLOBAL. This is necessary for debugging, because + // libjdwp.so need a symbol (fork1) from libjvm which it only gets if the jvm is loaded + // with RTLD_GLOBAL. On Solaris libjdwp.so is correctly linked with libjvm.so + osl::Module moduleRt; +#if defined(LINUX) + if (!moduleRt.load(sRuntimeLib, SAL_LOADMODULE_GLOBAL | SAL_LOADMODULE_NOW)) +#elif defined MACOSX + // Must be SAL_LOADMODULE_GLOBAL when e.g. specifying a + // -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 option to + // JDK 1.8.0_121 at least, as JNI_CreateJavaVM -> Threads::create_vm -> + // JvmtiExport::post_vm_initialized -> cbEarlyVMInit -> initialize -> + // util_initialize -> sun.misc.VMSupport.getAgentProperties -> + // Java_sun_misc_VMSupport_initAgentProperties -> + // JDK_FindJvmEntry("JVM_INitAgentProperties") -> + // dlsym(RTLD_DEFAULT, "JVM_INitAgentProperties"): + if (!moduleRt.load(sRuntimeLib, SAL_LOADMODULE_GLOBAL)) +#else +#if defined(_WIN32) + do_msvcr_magic(sRuntimeLib); +#endif + if (!moduleRt.load(sRuntimeLib)) +#endif + { + JFW_ENSURE(false, + "[Java framework]sunjavaplugin" SAL_DLLEXTENSION + " could not load Java runtime library: \n" + + sRuntimeLib + "\n"); + JFW_TRACE0("Could not load Java runtime library: " << sRuntimeLib); + return javaPluginError::VmCreationFailed; + } + +#if defined UNX && !defined MACOSX + //Setting the JAVA_HOME is needed for awt + OUString sPathLocation; + osl::FileBase::getSystemPathFromFileURL(pInfo->sLocation, sPathLocation); + osl_setEnvironment(OUString("JAVA_HOME").pData, sPathLocation.pData); +#endif + + OUString sSymbolCreateJava("JNI_CreateJavaVM"); + + JNI_CreateVM_Type * pCreateJavaVM = + reinterpret_cast(moduleRt.getFunctionSymbol(sSymbolCreateJava)); + if (!pCreateJavaVM) + { + OSL_ASSERT(false); + OString sLib = OUStringToOString( + sRuntimeLib, osl_getThreadTextEncoding()); + OString sSymbol = OUStringToOString( + sSymbolCreateJava, osl_getThreadTextEncoding()); + fprintf(stderr,"[Java framework]sunjavaplugin" SAL_DLLEXTENSION + "Java runtime library: %s does not export symbol %s !\n", + sLib.getStr(), sSymbol.getStr()); + return javaPluginError::VmCreationFailed; + } + moduleRt.release(); + + // Valgrind typically emits many false errors when executing JIT'ed JVM + // code, so force the JVM into interpreted mode: + bool addForceInterpreted = FORCE_INTERPRETED > 0; + + // Some testing with Java 1.4 showed that JavaVMOption.optionString has to + // be encoded with the system encoding (i.e., osl_getThreadTextEncoding): + JavaVMInitArgs vm_args; + + struct Option { + Option(OString const & theOptionString, void * theExtraInfo): + optionString(theOptionString), extraInfo(theExtraInfo) + {} + + OString optionString; + void * extraInfo; + }; + std::vector