src/java.base/macosx/native/libjli/java_md_macosx.m
author mbaesken
Thu, 28 Nov 2019 13:02:39 +0100
changeset 59323 ae2eb76c486d
parent 58280 ef8c8cf9256a
permissions -rw-r--r--
8234821: remove unused functions from libjli Reviewed-by: clanger, alanb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     1
/*
53941
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
     2
 * Copyright (c) 2012, 2019, Oracle and/or its affiliates. All rights reserved.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     4
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    10
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    15
 * accompanied this code).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    16
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    20
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    23
 * questions.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    24
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    25
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    26
#include "java.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    27
#include "jvm_md.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    28
#include <dirent.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    29
#include <dlfcn.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    30
#include <fcntl.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    31
#include <inttypes.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    32
#include <stdio.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    33
#include <string.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    34
#include <stdlib.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    35
#include <sys/stat.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    36
#include <unistd.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    37
#include <sys/types.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    38
#include <sys/time.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    39
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    40
#include "manifest_info.h"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    41
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    42
/* Support Cocoa event loop on the main thread */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    43
#include <Cocoa/Cocoa.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    44
#include <objc/objc-runtime.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    45
#include <objc/objc-auto.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    46
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    47
#include <errno.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    48
#include <spawn.h>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    49
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    50
struct NSAppArgs {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    51
    int argc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    52
    char **argv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    53
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    54
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    55
#define JVM_DLL "libjvm.dylib"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    56
#define JAVA_DLL "libjava.dylib"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    57
/* FALLBACK avoids naming conflicts with system libraries
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    58
 * (eg, ImageIO's libJPEG.dylib) */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    59
#define LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    60
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    61
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    62
 * If a processor / os combination has the ability to run binaries of
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    63
 * two data models and cohabitation of jre/jdk bits with both data
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    64
 * models is supported, then DUAL_MODE is defined. MacOSX is a hybrid
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    65
 * system in that, the universal library can contain all types of libraries
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    66
 * 32/64 and client/server, thus the spawn is capable of linking with the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    67
 * appropriate library as requested.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    68
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    69
 * Notes:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    70
 * 1. VM. DUAL_MODE is disabled, and not supported, however, it is left here in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    71
 *    for experimentation and perhaps enable it in the future.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    72
 * 2. At the time of this writing, the universal library contains only
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    73
 *    a server 64-bit server JVM.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    74
 * 3. "-client" command line option is supported merely as a command line flag,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    75
 *    for, compatibility reasons, however, a server VM will be launched.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    76
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    77
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    78
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    79
 * Flowchart of launcher execs and options processing on unix
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    80
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    81
 * The selection of the proper vm shared library to open depends on
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    82
 * several classes of command line options, including vm "flavor"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    83
 * options (-client, -server) and the data model options, -d32  and
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    84
 * -d64, as well as a version specification which may have come from
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    85
 * the command line or from the manifest of an executable jar file.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    86
 * The vm selection options are not passed to the running
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    87
 * virtual machine; they must be screened out by the launcher.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    88
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    89
 * The version specification (if any) is processed first by the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    90
 * platform independent routine SelectVersion.  This may result in
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    91
 * the exec of the specified launcher version.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    92
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    93
 * Now, in most cases,the launcher will dlopen the target libjvm.so. All
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    94
 * required libraries are loaded by the runtime linker, using the known paths
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    95
 * baked into the shared libraries at compile time. Therefore,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    96
 * in most cases, the launcher will only exec, if the data models are
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    97
 * mismatched, and will not set any environment variables, regardless of the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    98
 * data models.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
    99
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   100
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   101
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   102
 *  Main
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   103
 *  (incoming argv)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   104
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   105
 * \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   106
 * CreateExecutionEnvironment
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   107
 * (determines desired data model)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   108
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   109
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   110
 * \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   111
 *  Have Desired Model ? --> NO --> Is Dual-Mode ? --> NO --> Exit(with error)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   112
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   113
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   114
 *  |                                         \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   115
 *  |                                         YES
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   116
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   117
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   118
 *  |                                         \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   119
 *  |                                CheckJvmType
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   120
 *  |                               (removes -client, -server etc.)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   121
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   122
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   123
 * \|/                                        \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   124
 * YES                             Find the desired executable/library
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   125
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   126
 *  |                                          |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   127
 * \|/                                        \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   128
 * CheckJvmType                             POINT A
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   129
 * (removes -client, -server, etc.)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   130
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   131
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   132
 * \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   133
 * TranslateDashJArgs...
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   134
 * (Prepare to pass args to vm)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   135
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   136
 *  |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   137
 * \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   138
 * ParseArguments
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   139
 * (processes version options,
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   140
 *  creates argument list for vm,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   141
 *  etc.)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   142
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   143
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   144
 *  \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   145
 * POINT A
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   146
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   147
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   148
 *  \|/
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   149
 * Path is desired JRE ? YES --> Continue
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   150
 *  NO
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   151
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   152
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   153
 *  \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   154
 * Paths have well known
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   155
 * jvm paths ?       --> NO --> Continue
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   156
 *  YES
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   157
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   158
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   159
 *  \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   160
 *  Does libjvm.so exist
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   161
 *  in any of them ? --> NO --> Continue
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   162
 *   YES
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   163
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   164
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   165
 *  \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   166
 * Re-exec / Spawn
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   167
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   168
 *   |
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   169
 *  \|/
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   170
 * Main
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   171
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   172
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   173
/* Store the name of the executable once computed */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   174
static char *execname = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   175
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   176
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   177
 * execname accessor from other parts of platform dependent logic
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   178
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   179
const char *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   180
GetExecName() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   181
    return execname;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   182
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   183
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   184
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   185
 * Exports the JNI interface from libjli
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   186
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   187
 * This allows client code to link against the .jre/.jdk bundles,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   188
 * and not worry about trying to pick a HotSpot to link against.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   189
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   190
 * Switching architectures is unsupported, since client code has
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   191
 * made that choice before the JVM was requested.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   192
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   193
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   194
static InvocationFunctions *sExportedJNIFunctions = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   195
static char *sPreferredJVMType = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   196
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   197
static InvocationFunctions *GetExportedJNIFunctions() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   198
    if (sExportedJNIFunctions != NULL) return sExportedJNIFunctions;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   199
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   200
    char jrePath[PATH_MAX];
42753
40f61533b93d 8066474: Remove the lib/ directory from Linux and Solaris images
erikj
parents: 39534
diff changeset
   201
    jboolean gotJREPath = GetJREPath(jrePath, sizeof(jrePath), JNI_FALSE);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   202
    if (!gotJREPath) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   203
        JLI_ReportErrorMessage("Failed to GetJREPath()");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   204
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   205
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   206
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   207
    char *preferredJVM = sPreferredJVMType;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   208
    if (preferredJVM == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   209
#if defined(__i386__)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   210
        preferredJVM = "client";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   211
#elif defined(__x86_64__)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   212
        preferredJVM = "server";
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   213
#else
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   214
#error "Unknown architecture - needs definition"
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   215
#endif
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   216
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   217
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   218
    char jvmPath[PATH_MAX];
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   219
    jboolean gotJVMPath = GetJVMPath(jrePath, preferredJVM, jvmPath, sizeof(jvmPath));
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   220
    if (!gotJVMPath) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   221
        JLI_ReportErrorMessage("Failed to GetJVMPath()");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   222
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   223
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   224
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   225
    InvocationFunctions *fxns = malloc(sizeof(InvocationFunctions));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   226
    jboolean vmLoaded = LoadJavaVM(jvmPath, fxns);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   227
    if (!vmLoaded) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   228
        JLI_ReportErrorMessage("Failed to LoadJavaVM()");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   229
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   230
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   231
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   232
    return sExportedJNIFunctions = fxns;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   233
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   234
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   235
#ifndef STATIC_BUILD
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   236
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   237
JNIEXPORT jint JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   238
JNI_GetDefaultJavaVMInitArgs(void *args) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   239
    InvocationFunctions *ifn = GetExportedJNIFunctions();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   240
    if (ifn == NULL) return JNI_ERR;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   241
    return ifn->GetDefaultJavaVMInitArgs(args);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   242
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   243
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   244
JNIEXPORT jint JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   245
JNI_CreateJavaVM(JavaVM **pvm, void **penv, void *args) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   246
    InvocationFunctions *ifn = GetExportedJNIFunctions();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   247
    if (ifn == NULL) return JNI_ERR;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   248
    return ifn->CreateJavaVM(pvm, penv, args);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   249
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   250
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   251
JNIEXPORT jint JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   252
JNI_GetCreatedJavaVMs(JavaVM **vmBuf, jsize bufLen, jsize *nVMs) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   253
    InvocationFunctions *ifn = GetExportedJNIFunctions();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   254
    if (ifn == NULL) return JNI_ERR;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   255
    return ifn->GetCreatedJavaVMs(vmBuf, bufLen, nVMs);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   256
}
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   257
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   258
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   259
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   260
 * Allow JLI-aware launchers to specify a client/server preference
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   261
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   262
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   263
JLI_SetPreferredJVM(const char *prefJVM) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   264
    if (sPreferredJVMType != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   265
        free(sPreferredJVMType);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   266
        sPreferredJVMType = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   267
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   268
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   269
    if (prefJVM == NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   270
    sPreferredJVMType = strdup(prefJVM);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   271
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   272
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   273
static BOOL awtLoaded = NO;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   274
static pthread_mutex_t awtLoaded_mutex = PTHREAD_MUTEX_INITIALIZER;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   275
static pthread_cond_t  awtLoaded_cv = PTHREAD_COND_INITIALIZER;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   276
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   277
JNIEXPORT void JNICALL
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   278
JLI_NotifyAWTLoaded()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   279
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   280
    pthread_mutex_lock(&awtLoaded_mutex);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   281
    awtLoaded = YES;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   282
    pthread_cond_signal(&awtLoaded_cv);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   283
    pthread_mutex_unlock(&awtLoaded_mutex);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   284
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   285
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   286
static int (*main_fptr)(int argc, char **argv) = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   287
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   288
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   289
 * Unwrap the arguments and re-run main()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   290
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   291
static void *apple_main (void *arg)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   292
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   293
    if (main_fptr == NULL) {
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   294
#ifdef STATIC_BUILD
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   295
        extern int main(int argc, char **argv);
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   296
        main_fptr = &main;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   297
#else
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   298
        main_fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   299
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   300
        if (main_fptr == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   301
            JLI_ReportErrorMessageSys("error locating main entrypoint\n");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   302
            exit(1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   303
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   304
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   305
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   306
    struct NSAppArgs *args = (struct NSAppArgs *) arg;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   307
    exit(main_fptr(args->argc, args->argv));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   308
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   309
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   310
static void dummyTimer(CFRunLoopTimerRef timer, void *info) {}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   311
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   312
static void ParkEventLoop() {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   313
    // RunLoop needs at least one source, and 1e20 is pretty far into the future
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   314
    CFRunLoopTimerRef t = CFRunLoopTimerCreate(kCFAllocatorDefault, 1.0e20, 0.0, 0, 0, dummyTimer, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   315
    CFRunLoopAddTimer(CFRunLoopGetCurrent(), t, kCFRunLoopDefaultMode);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   316
    CFRelease(t);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   317
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   318
    // Park this thread in the main run loop.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   319
    int32_t result;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   320
    do {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   321
        result = CFRunLoopRunInMode(kCFRunLoopDefaultMode, 1.0e20, false);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   322
    } while (result != kCFRunLoopRunFinished);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   323
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   324
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   325
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   326
 * Mac OS X mandates that the GUI event loop run on very first thread of
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   327
 * an application. This requires that we re-call Java's main() on a new
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   328
 * thread, reserving the 'main' thread for Cocoa.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   329
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   330
static void MacOSXStartup(int argc, char *argv[]) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   331
    // Thread already started?
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   332
    static jboolean started = false;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   333
    if (started) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   334
        return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   335
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   336
    started = true;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   337
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   338
    // Hand off arguments
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   339
    struct NSAppArgs args;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   340
    args.argc = argc;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   341
    args.argv = argv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   342
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   343
    // Fire up the main thread
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   344
    pthread_t main_thr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   345
    if (pthread_create(&main_thr, NULL, &apple_main, &args) != 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   346
        JLI_ReportErrorMessageSys("Could not create main thread: %s\n", strerror(errno));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   347
        exit(1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   348
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   349
    if (pthread_detach(main_thr)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   350
        JLI_ReportErrorMessageSys("pthread_detach() failed: %s\n", strerror(errno));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   351
        exit(1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   352
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   353
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   354
    ParkEventLoop();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   355
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   356
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   357
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   358
CreateExecutionEnvironment(int *pargc, char ***pargv,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   359
                           char jrepath[], jint so_jrepath,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   360
                           char jvmpath[], jint so_jvmpath,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   361
                           char jvmcfg[],  jint so_jvmcfg) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   362
    jboolean jvmpathExists;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   363
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   364
    /* Compute/set the name of the executable */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   365
    SetExecname(*pargv);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   366
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   367
    char * jvmtype    = NULL;
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   368
    int  argc         = *pargc;
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   369
    char **argv       = *pargv;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   370
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   371
    /* Find out where the JRE is that we will be using. */
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   372
    if (!GetJREPath(jrepath, so_jrepath, JNI_FALSE) ) {
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   373
        JLI_ReportErrorMessage(JRE_ERROR1);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   374
        exit(2);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   375
    }
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   376
    JLI_Snprintf(jvmcfg, so_jvmcfg, "%s%slib%sjvm.cfg",
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   377
                 jrepath, FILESEP, FILESEP);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   378
    /* Find the specified JVM type */
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   379
    if (ReadKnownVMs(jvmcfg, JNI_FALSE) < 1) {
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   380
        JLI_ReportErrorMessage(CFG_ERROR7);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   381
        exit(1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   382
    }
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   383
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   384
    jvmpath[0] = '\0';
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   385
    jvmtype = CheckJvmType(pargc, pargv, JNI_FALSE);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   386
    if (JLI_StrCmp(jvmtype, "ERROR") == 0) {
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   387
        JLI_ReportErrorMessage(CFG_ERROR9);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   388
        exit(4);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   389
    }
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   390
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   391
    if (!GetJVMPath(jrepath, jvmtype, jvmpath, so_jvmpath)) {
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   392
        JLI_ReportErrorMessage(CFG_ERROR8, jvmtype, jvmpath);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   393
        exit(4);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   394
    }
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   395
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   396
    /*
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   397
     * Mac OS X requires the Cocoa event loop to be run on the "main"
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   398
     * thread. Spawn off a new thread to run main() and pass
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   399
     * this thread off to the Cocoa event loop.
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   400
     */
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   401
    MacOSXStartup(argc, argv);
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   402
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   403
    /*
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   404
     * we seem to have everything we need
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   405
     */
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   406
    return;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   407
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   408
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   409
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   410
 * VM choosing is done by the launcher (java.c).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   411
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   412
static jboolean
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   413
GetJVMPath(const char *jrepath, const char *jvmtype,
45062
37ed4313c8c1 8169646: Remove launcher's -d32/-d64 option
ksrini
parents: 42755
diff changeset
   414
           char *jvmpath, jint jvmpathsize)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   415
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   416
    struct stat s;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   417
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   418
    if (JLI_StrChr(jvmtype, '/')) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   419
        JLI_Snprintf(jvmpath, jvmpathsize, "%s/" JVM_DLL, jvmtype);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   420
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   421
        /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   422
         * macosx client library is built thin, i386 only.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   423
         * 64 bit client requests must load server library
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   424
         */
45071
f0579c053626 8180202: -XXaltjvm is not working anymore on MacOSX
ksrini
parents: 45062
diff changeset
   425
        JLI_Snprintf(jvmpath, jvmpathsize, "%s/lib/%s/" JVM_DLL, jrepath, jvmtype);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   426
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   427
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   428
    JLI_TraceLauncher("Does `%s' exist ... ", jvmpath);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   429
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   430
#ifdef STATIC_BUILD
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   431
    return JNI_TRUE;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   432
#else
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   433
    if (stat(jvmpath, &s) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   434
        JLI_TraceLauncher("yes.\n");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   435
        return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   436
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   437
        JLI_TraceLauncher("no.\n");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   438
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   439
    }
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   440
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   441
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   442
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   443
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   444
 * Find path to JRE based on .exe's location or registry settings.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   445
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   446
static jboolean
42753
40f61533b93d 8066474: Remove the lib/ directory from Linux and Solaris images
erikj
parents: 39534
diff changeset
   447
GetJREPath(char *path, jint pathsize, jboolean speculative)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   448
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   449
    char libjava[MAXPATHLEN];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   450
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   451
    if (GetApplicationHome(path, pathsize)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   452
        /* Is JRE co-located with the application? */
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   453
#ifdef STATIC_BUILD
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   454
        char jvm_cfg[MAXPATHLEN];
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   455
        JLI_Snprintf(jvm_cfg, sizeof(jvm_cfg), "%s/lib/jvm.cfg", path);
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   456
        if (access(jvm_cfg, F_OK) == 0) {
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   457
            return JNI_TRUE;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   458
        }
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   459
#else
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   460
        JLI_Snprintf(libjava, sizeof(libjava), "%s/lib/" JAVA_DLL, path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   461
        if (access(libjava, F_OK) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   462
            return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   463
        }
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   464
#endif
31690
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30467
diff changeset
   465
        /* ensure storage for path + /jre + NULL */
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30467
diff changeset
   466
        if ((JLI_StrLen(path) + 4 + 1) > (size_t) pathsize) {
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30467
diff changeset
   467
            JLI_TraceLauncher("Insufficient space to store JRE path\n");
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30467
diff changeset
   468
            return JNI_FALSE;
3944eaf3322c 8073773: Presume path preparedness
ksrini
parents: 30467
diff changeset
   469
        }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   470
        /* Does the app ship a private JRE in <apphome>/jre directory? */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   471
        JLI_Snprintf(libjava, sizeof(libjava), "%s/jre/lib/" JAVA_DLL, path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   472
        if (access(libjava, F_OK) == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   473
            JLI_StrCat(path, "/jre");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   474
            JLI_TraceLauncher("JRE path is %s\n", path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   475
            return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   476
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   477
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   478
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   479
    /* try to find ourselves instead */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   480
    Dl_info selfInfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   481
    dladdr(&GetJREPath, &selfInfo);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   482
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   483
#ifdef STATIC_BUILD
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   484
    char jvm_cfg[MAXPATHLEN];
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   485
    char *p = NULL;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   486
    strncpy(jvm_cfg, selfInfo.dli_fname, MAXPATHLEN);
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   487
    p = strrchr(jvm_cfg, '/'); *p = '\0';
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   488
    p = strrchr(jvm_cfg, '/');
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   489
    if (strcmp(p, "/.") == 0) {
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   490
      *p = '\0';
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   491
      p = strrchr(jvm_cfg, '/'); *p = '\0';
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   492
    }
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   493
    else *p = '\0';
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   494
    strncpy(path, jvm_cfg, pathsize);
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   495
    strncat(jvm_cfg, "/lib/jvm.cfg", MAXPATHLEN);
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   496
    if (access(jvm_cfg, F_OK) == 0) {
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   497
      return JNI_TRUE;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   498
    }
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   499
#endif
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   500
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   501
    char *realPathToSelf = realpath(selfInfo.dli_fname, path);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   502
    if (realPathToSelf != path) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   503
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   504
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   505
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   506
    size_t pathLen = strlen(realPathToSelf);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   507
    if (pathLen == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   508
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   509
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   510
52788
241b8151b6b6 8213362: [macOS] Could not find libjava.dylib error when initializing JVM via JNI_CreateJavaVM
henryjen
parents: 52264
diff changeset
   511
    const char lastPathComponent[] = "/lib/libjli.dylib";
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   512
    size_t sizeOfLastPathComponent = sizeof(lastPathComponent) - 1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   513
    if (pathLen < sizeOfLastPathComponent) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   514
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   515
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   516
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   517
    size_t indexOfLastPathComponent = pathLen - sizeOfLastPathComponent;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   518
    if (0 == strncmp(realPathToSelf + indexOfLastPathComponent, lastPathComponent, sizeOfLastPathComponent - 1)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   519
        realPathToSelf[indexOfLastPathComponent + 1] = '\0';
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   520
        return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   521
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   522
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   523
    if (!speculative)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   524
      JLI_ReportErrorMessage(JRE_ERROR8 JAVA_DLL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   525
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   526
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   527
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   528
jboolean
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   529
LoadJavaVM(const char *jvmpath, InvocationFunctions *ifn)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   530
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   531
    Dl_info dlinfo;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   532
    void *libjvm;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   533
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   534
    JLI_TraceLauncher("JVM path is %s\n", jvmpath);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   535
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   536
#ifndef STATIC_BUILD
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   537
    libjvm = dlopen(jvmpath, RTLD_NOW + RTLD_GLOBAL);
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   538
#else
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   539
    libjvm = dlopen(NULL, RTLD_FIRST);
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   540
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   541
    if (libjvm == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   542
        JLI_ReportErrorMessage(DLL_ERROR1, __LINE__);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   543
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   544
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   545
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   546
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   547
    ifn->CreateJavaVM = (CreateJavaVM_t)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   548
        dlsym(libjvm, "JNI_CreateJavaVM");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   549
    if (ifn->CreateJavaVM == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   550
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   551
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   552
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   553
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   554
    ifn->GetDefaultJavaVMInitArgs = (GetDefaultJavaVMInitArgs_t)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   555
        dlsym(libjvm, "JNI_GetDefaultJavaVMInitArgs");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   556
    if (ifn->GetDefaultJavaVMInitArgs == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   557
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   558
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   559
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   560
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   561
    ifn->GetCreatedJavaVMs = (GetCreatedJavaVMs_t)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   562
    dlsym(libjvm, "JNI_GetCreatedJavaVMs");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   563
    if (ifn->GetCreatedJavaVMs == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   564
        JLI_ReportErrorMessage(DLL_ERROR2, jvmpath, dlerror());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   565
        return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   566
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   567
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   568
    return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   569
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   570
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   571
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   572
 * Compute the name of the executable
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   573
 *
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   574
 * In order to re-exec securely we need the absolute path of the
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   575
 * executable. On Solaris getexecname(3c) may not return an absolute
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   576
 * path so we use dladdr to get the filename of the executable and
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   577
 * then use realpath to derive an absolute path. From Solaris 9
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   578
 * onwards the filename returned in DL_info structure from dladdr is
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   579
 * an absolute pathname so technically realpath isn't required.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   580
 * On Linux we read the executable name from /proc/self/exe.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   581
 * As a fallback, and for platforms other than Solaris and Linux,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   582
 * we use FindExecName to compute the executable name.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   583
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   584
const char*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   585
SetExecname(char **argv)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   586
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   587
    char* exec_path = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   588
    {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   589
        Dl_info dlinfo;
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   590
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   591
#ifdef STATIC_BUILD
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   592
        void *fptr;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   593
        fptr = (void *)&SetExecname;
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   594
#else
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   595
        int (*fptr)();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   596
        fptr = (int (*)())dlsym(RTLD_DEFAULT, "main");
33653
c1ee09fe3274 8136556: Add the ability to perform static builds of MacOSX x64 binaries
bobv
parents: 31690
diff changeset
   597
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   598
        if (fptr == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   599
            JLI_ReportErrorMessage(DLL_ERROR3, dlerror());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   600
            return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   601
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   602
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   603
        if (dladdr((void*)fptr, &dlinfo)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   604
            char *resolved = (char*)JLI_MemAlloc(PATH_MAX+1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   605
            if (resolved != NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   606
                exec_path = realpath(dlinfo.dli_fname, resolved);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   607
                if (exec_path == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   608
                    JLI_MemFree(resolved);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   609
                }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   610
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   611
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   612
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   613
    if (exec_path == NULL) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   614
        exec_path = FindExecName(argv[0]);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   615
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   616
    execname = exec_path;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   617
    return exec_path;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   618
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   619
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   620
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   621
 * BSD's implementation of CounterGet()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   622
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   623
int64_t
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   624
CounterGet()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   625
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   626
    struct timeval tv;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   627
    gettimeofday(&tv, NULL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   628
    return (tv.tv_sec * 1000) + tv.tv_usec;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   629
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   630
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   631
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   632
/* --- Splash Screen shared library support --- */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   633
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   634
static JavaVM* SetJavaVMValue()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   635
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   636
    JavaVM * jvm = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   637
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   638
    // The handle is good for both the launcher and the libosxapp.dylib
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   639
    void * handle = dlopen(NULL, RTLD_LAZY | RTLD_GLOBAL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   640
    if (handle) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   641
        typedef JavaVM* (*JLI_GetJavaVMInstance_t)();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   642
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   643
        JLI_GetJavaVMInstance_t JLI_GetJavaVMInstance =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   644
            (JLI_GetJavaVMInstance_t)dlsym(handle,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   645
                    "JLI_GetJavaVMInstance");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   646
        if (JLI_GetJavaVMInstance) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   647
            jvm = JLI_GetJavaVMInstance();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   648
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   649
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   650
        if (jvm) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   651
            typedef void (*OSXAPP_SetJavaVM_t)(JavaVM*);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   652
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   653
            OSXAPP_SetJavaVM_t OSXAPP_SetJavaVM =
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   654
                (OSXAPP_SetJavaVM_t)dlsym(handle, "OSXAPP_SetJavaVM");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   655
            if (OSXAPP_SetJavaVM) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   656
                OSXAPP_SetJavaVM(jvm);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   657
            } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   658
                jvm = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   659
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   660
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   661
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   662
        dlclose(handle);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   663
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   664
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   665
    return jvm;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   666
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   667
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   668
static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   669
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   670
static void* hSplashLib = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   671
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   672
void* SplashProcAddress(const char* name) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   673
    if (!hSplashLib) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   674
        char jrePath[PATH_MAX];
42753
40f61533b93d 8066474: Remove the lib/ directory from Linux and Solaris images
erikj
parents: 39534
diff changeset
   675
        if (!GetJREPath(jrePath, sizeof(jrePath), JNI_FALSE)) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   676
            JLI_ReportErrorMessage(JRE_ERROR1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   677
            return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   678
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   679
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   680
        char splashPath[PATH_MAX];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   681
        const int ret = JLI_Snprintf(splashPath, sizeof(splashPath),
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   682
                "%s/lib/%s", jrePath, SPLASHSCREEN_SO);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   683
        if (ret >= (int)sizeof(splashPath)) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   684
            JLI_ReportErrorMessage(JRE_ERROR11);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   685
            return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   686
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   687
        if (ret < 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   688
            JLI_ReportErrorMessage(JRE_ERROR13);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   689
            return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   690
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   691
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   692
        hSplashLib = dlopen(splashPath, RTLD_LAZY | RTLD_GLOBAL);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   693
        // It's OK if dlopen() fails. The splash screen library binary file
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   694
        // might have been stripped out from the JRE image to reduce its size
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   695
        // (e.g. on embedded platforms).
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   696
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   697
        if (hSplashLib) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   698
            if (!SetJavaVMValue()) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   699
                dlclose(hSplashLib);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   700
                hSplashLib = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   701
            }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   702
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   703
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   704
    if (hSplashLib) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   705
        void* sym = dlsym(hSplashLib, name);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   706
        return sym;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   707
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   708
        return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   709
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   710
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   711
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   712
/*
53941
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   713
 * Signature adapter for pthread_create().
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   714
 */
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   715
static void* ThreadJavaMain(void* args) {
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   716
    return (void*)(intptr_t)JavaMain(args);
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   717
}
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   718
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   719
/*
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   720
 * Block current thread and continue execution in a new thread.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   721
 */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   722
int
53941
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   723
CallJavaMainInNewThread(jlong stack_size, void* args) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   724
    int rslt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   725
    pthread_t tid;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   726
    pthread_attr_t attr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   727
    pthread_attr_init(&attr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   728
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   729
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   730
    if (stack_size > 0) {
53941
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   731
        pthread_attr_setstacksize(&attr, stack_size);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   732
    }
46846
292be53258b7 8175342: assert(InstanceKlass::cast(k)->is_initialized()) failed: need to increase java_thread_min_stack_allowed calculation
cjplummer
parents: 42755
diff changeset
   733
    pthread_attr_setguardsize(&attr, 0); // no pthread guard page on java threads
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   734
53941
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   735
    if (pthread_create(&tid, &attr, ThreadJavaMain, args) == 0) {
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   736
        void* tmp;
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   737
        pthread_join(tid, &tmp);
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   738
        rslt = (int)(intptr_t)tmp;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   739
    } else {
53941
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   740
       /*
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   741
        * Continue execution in current thread if for some reason (e.g. out of
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   742
        * memory/LWP)  a new thread can't be created. This will likely fail
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   743
        * later in JavaMain as JNI_CreateJavaVM needs to create quite a
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   744
        * few new threads, anyway, just give it a try..
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   745
        */
f9302cf718c9 8215009: GCC 8 compilation error in libjli
dchuyko
parents: 52788
diff changeset
   746
        rslt = JavaMain(args);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   747
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   748
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   749
    pthread_attr_destroy(&attr);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   750
    return rslt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   751
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   752
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   753
static JavaVM* jvmInstance = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   754
static jboolean sameThread = JNI_FALSE; /* start VM in current thread */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   755
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   756
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   757
 * Note there is a callback on this function from the splashscreen logic,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   758
 * this as well SetJavaVMValue() needs to be simplified.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   759
 */
52264
d6c322e900b2 8212213: All tests for splashscreen stopped worked in jdk12b13
serb
parents: 51825
diff changeset
   760
JNIEXPORT JavaVM* JNICALL
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   761
JLI_GetJavaVMInstance()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   762
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   763
    return jvmInstance;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   764
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   765
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   766
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   767
RegisterThread()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   768
{
46874
13b399635568 8182299: Enable disabled clang warnings, build on OSX 10 + Xcode 8
phh
parents: 46865
diff changeset
   769
    // stubbed out for windows and *nixes.
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   770
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   771
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   772
static void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   773
SetXDockArgForAWT(const char *arg)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   774
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   775
    char envVar[80];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   776
    if (strstr(arg, "-Xdock:name=") == arg) {
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   777
        /*
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   778
         * The APP_NAME_<pid> environment variable is used to pass
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   779
         * an application name as specified with the -Xdock:name command
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   780
         * line option from Java launcher code to the AWT code in order
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   781
         * to assign this name to the app's dock tile on the Mac.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   782
         * The _<pid> part is added to avoid collisions with child processes.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   783
         *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   784
         * WARNING: This environment variable is an implementation detail and
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   785
         * isn't meant for use outside of the core platform. The mechanism for
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   786
         * passing this information from Java launcher to other modules may
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   787
         * change drastically between update release, and it may even be
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   788
         * removed or replaced with another mechanism.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   789
         *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   790
         * NOTE: It is used by SWT, and JavaFX.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   791
         */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   792
        snprintf(envVar, sizeof(envVar), "APP_NAME_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   793
        setenv(envVar, (arg + 12), 1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   794
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   795
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   796
    if (strstr(arg, "-Xdock:icon=") == arg) {
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   797
        /*
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   798
         * The APP_ICON_<pid> environment variable is used to pass
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   799
         * an application icon as specified with the -Xdock:icon command
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   800
         * line option from Java launcher code to the AWT code in order
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   801
         * to assign this icon to the app's dock tile on the Mac.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   802
         * The _<pid> part is added to avoid collisions with child processes.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   803
         *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   804
         * WARNING: This environment variable is an implementation detail and
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   805
         * isn't meant for use outside of the core platform. The mechanism for
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   806
         * passing this information from Java launcher to other modules may
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   807
         * change drastically between update release, and it may even be
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   808
         * removed or replaced with another mechanism.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   809
         *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   810
         * NOTE: It is used by SWT, and JavaFX.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   811
         */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   812
        snprintf(envVar, sizeof(envVar), "APP_ICON_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   813
        setenv(envVar, (arg + 12), 1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   814
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   815
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   816
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   817
static void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   818
SetMainClassForAWT(JNIEnv *env, jclass mainClass) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   819
    jclass classClass = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   820
    NULL_CHECK(classClass = FindBootStrapClass(env, "java/lang/Class"));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   821
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   822
    jmethodID getCanonicalNameMID = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   823
    NULL_CHECK(getCanonicalNameMID = (*env)->GetMethodID(env, classClass, "getCanonicalName", "()Ljava/lang/String;"));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   824
30467
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   825
    jstring mainClassString = (*env)->CallObjectMethod(env, mainClass, getCanonicalNameMID);
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   826
    if ((*env)->ExceptionCheck(env)) {
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   827
        /*
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   828
         * Clears all errors caused by getCanonicalName() on the mainclass and
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   829
         * leaves the JAVA_MAIN_CLASS__<pid> empty.
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   830
         */
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   831
        (*env)->ExceptionClear(env);
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   832
        return;
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   833
    }
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   834
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   835
    const char *mainClassName = NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   836
    NULL_CHECK(mainClassName = (*env)->GetStringUTFChars(env, mainClassString, NULL));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   837
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   838
    char envVar[80];
12527
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   839
    /*
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   840
     * The JAVA_MAIN_CLASS_<pid> environment variable is used to pass
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   841
     * the name of a Java class whose main() method is invoked by
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   842
     * the Java launcher code to start the application, to the AWT code
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   843
     * in order to assign the name to the Apple menu bar when the app
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   844
     * is active on the Mac.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   845
     * The _<pid> part is added to avoid collisions with child processes.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   846
     *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   847
     * WARNING: This environment variable is an implementation detail and
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   848
     * isn't meant for use outside of the core platform. The mechanism for
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   849
     * passing this information from Java launcher to other modules may
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   850
     * change drastically between update release, and it may even be
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   851
     * removed or replaced with another mechanism.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   852
     *
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   853
     * NOTE: It is used by SWT, and JavaFX.
22abaf748b5b 7131021: [macosx] Consider using system properties to pass arguments from the launcher to AWT/SplashScreen
anthony
parents: 12047
diff changeset
   854
     */
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   855
    snprintf(envVar, sizeof(envVar), "JAVA_MAIN_CLASS_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   856
    setenv(envVar, mainClassName, 1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   857
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   858
    (*env)->ReleaseStringUTFChars(env, mainClassString, mainClassName);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   859
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   860
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   861
void
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   862
SetXStartOnFirstThreadArg()
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   863
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   864
    // XXX: BEGIN HACK
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   865
    // short circuit hack for <https://bugs.eclipse.org/bugs/show_bug.cgi?id=211625>
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   866
    // need a way to get AWT/Swing apps launched when spawned from Eclipse,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   867
    // which currently has no UI to not pass the -XstartOnFirstThread option
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   868
    if (getenv("HACK_IGNORE_START_ON_FIRST_THREAD") != NULL) return;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   869
    // XXX: END HACK
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   870
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   871
    sameThread = JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   872
    // Set a variable that tells us we started on the main thread.
25563
248400a88627 8033367: [macosx] Appletviewer was broken in jdk8 b124
pchelko
parents: 23010
diff changeset
   873
    // This is used by the AWT during startup. (See LWCToolkit.m)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   874
    char envVar[80];
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   875
    snprintf(envVar, sizeof(envVar), "JAVA_STARTED_ON_FIRST_THREAD_%d", getpid());
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   876
    setenv(envVar, "1", 1);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   877
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   878
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   879
// MacOSX we may continue in the same thread
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   880
int
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   881
JVMInit(InvocationFunctions* ifn, jlong threadStackSize,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   882
                 int argc, char **argv,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   883
                 int mode, char *what, int ret) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   884
    if (sameThread) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   885
        JLI_TraceLauncher("In same thread\n");
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   886
        // need to block this thread against the main thread
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   887
        // so signals get caught correctly
39534
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   888
        __block int rslt = 0;
17688
4b8f0d9b9cbc 8009911: [macosx] SWT app freeze when going full screen using Java 7 on Mac
pchelko
parents: 12527
diff changeset
   889
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
4b8f0d9b9cbc 8009911: [macosx] SWT app freeze when going full screen using Java 7 on Mac
pchelko
parents: 12527
diff changeset
   890
        {
39534
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   891
            NSBlockOperation *op = [NSBlockOperation blockOperationWithBlock: ^{
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   892
                JavaMainArgs args;
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   893
                args.argc = argc;
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   894
                args.argv = argv;
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   895
                args.mode = mode;
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   896
                args.what = what;
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   897
                args.ifn  = *ifn;
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   898
                rslt = JavaMain(&args);
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   899
            }];
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   900
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   901
            /*
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   902
             * We cannot use dispatch_sync here, because it blocks the main dispatch queue.
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   903
             * Using the main NSRunLoop allows the dispatch queue to run properly once
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   904
             * SWT (or whatever toolkit this is needed for) kicks off it's own NSRunLoop
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   905
             * and starts running.
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   906
             */
b12e60ec4e0f 8022291: Mac OS: Unexpected JavaLaunchHelper message displaying
ddehaven
parents: 33653
diff changeset
   907
            [op performSelectorOnMainThread:@selector(start) withObject:nil waitUntilDone:YES];
17688
4b8f0d9b9cbc 8009911: [macosx] SWT app freeze when going full screen using Java 7 on Mac
pchelko
parents: 12527
diff changeset
   908
        }
4b8f0d9b9cbc 8009911: [macosx] SWT app freeze when going full screen using Java 7 on Mac
pchelko
parents: 12527
diff changeset
   909
        [pool drain];
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   910
        return rslt;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   911
    } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   912
        return ContinueInNewThread(ifn, threadStackSize, argc, argv, mode, what, ret);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   913
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   914
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   915
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   916
/*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   917
 * Note the jvmInstance must be initialized first before entering into
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   918
 * ShowSplashScreen, as there is a callback into the JLI_GetJavaVMInstance.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   919
 */
30467
075f4f160f19 8076264: [macosx] Launching app on MacOSX requires enclosing class
serb
parents: 29742
diff changeset
   920
void PostJVMInit(JNIEnv *env, jclass mainClass, JavaVM *vm) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   921
    jvmInstance = vm;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   922
    SetMainClassForAWT(env, mainClass);
28771
2885fb2e1002 8068033: JNI exception pending in jdk/src/share/bin/java.c
ksrini
parents: 27938
diff changeset
   923
    CHECK_EXCEPTION_RETURN();
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   924
    ShowSplashScreen();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   925
}
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   926
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   927
jboolean
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   928
ProcessPlatformOption(const char* arg)
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   929
{
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   930
    if (JLI_StrCmp(arg, "-XstartOnFirstThread") == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   931
       SetXStartOnFirstThreadArg();
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   932
       return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   933
    } else if (JLI_StrCCmp(arg, "-Xdock:") == 0) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   934
       SetXDockArgForAWT(arg);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   935
       return JNI_TRUE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   936
    }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   937
    // arguments we know not
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   938
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents:
diff changeset
   939
}