src/java.rmi/share/classes/sun/rmi/server/UnicastServerRef.java
author rehn
Fri, 29 Nov 2019 12:09:25 +0100
changeset 59325 3636bab5e81e
parent 54556 30503c380394
permissions -rw-r--r--
8234086: VM operation can be simplified Reviewed-by: kbarrett, dholmes, dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54556
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
     2
 * Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.rmi.server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.ObjectInput;
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
    30
import java.io.ObjectInputFilter;
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
    31
import java.io.ObjectInputStream;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.io.ObjectOutput;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.lang.reflect.Method;
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
    35
import java.rmi.AccessException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.MarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.rmi.ServerError;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.rmi.ServerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.rmi.server.ExportException;
54556
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
    43
import java.rmi.server.Operation;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.rmi.server.RemoteCall;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.rmi.server.RemoteRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.rmi.server.RemoteStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.rmi.server.ServerNotActiveException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.rmi.server.ServerRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.rmi.server.Skeleton;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.rmi.server.SkeletonNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.WeakHashMap;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    58
import java.util.concurrent.atomic.AtomicInteger;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import sun.rmi.runtime.Log;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import sun.rmi.transport.LiveRef;
45984
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 41231
diff changeset
    61
import sun.rmi.transport.StreamRemoteCall;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import sun.rmi.transport.Target;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import sun.rmi.transport.tcp.TCPTransport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * UnicastServerRef implements the remote reference layer server-side
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * behavior for remote objects exported with the "UnicastRef" reference
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * type.
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
    69
 * If an {@link ObjectInputFilter ObjectInputFilter} is supplied it is
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
    70
 * invoked during deserialization to filter the arguments,
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
    71
 * otherwise the default filter of {@link ObjectInputStream ObjectInputStream}
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
    72
 * applies.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * @author  Ann Wollrath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * @author  Roger Riggs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * @author  Peter Jones
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 */
19211
32a04c562026 8022440: suppress deprecation warnings in sun.rmi
smarks
parents: 14342
diff changeset
    78
@SuppressWarnings("deprecation")
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
public class UnicastServerRef extends UnicastRef
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    implements ServerRef, Dispatcher
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    /** value of server call log property */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    public static final boolean logCalls = AccessController.doPrivileged(
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    84
        (PrivilegedAction<Boolean>) () -> Boolean.getBoolean("java.rmi.server.logCalls"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /** server call log */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static final Log callLog =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Log.getLog("sun.rmi.server.call", "RMI", logCalls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    // use serialVersionUID from JDK 1.2.2 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    private static final long serialVersionUID = -7384275867073752268L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /** flag to enable writing exceptions to System.err */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    private static final boolean wantExceptionLog =
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    95
        AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
    96
            Boolean.getBoolean("sun.rmi.server.exceptionTrace"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    private boolean forceStubUse = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * flag to remove server-side stack traces before marshalling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * exceptions thrown by remote invocations to this VM
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    private static final boolean suppressStackTraces =
23333
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
   105
        AccessController.doPrivileged((PrivilegedAction<Boolean>) () ->
b0af2c7c8c91 8035808: Eliminate dependency to GetPropertyAction and other sun.security.action convenient classes
mchung
parents: 21655
diff changeset
   106
            Boolean.getBoolean("sun.rmi.server.suppressStackTraces"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * skeleton to dispatch remote calls through, for 1.1 stub protocol
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * (may be null if stub class only uses 1.2 stub protocol)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    private transient Skeleton skel;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   114
    // The ObjectInputFilter for checking the invocation arguments
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   115
    private final transient ObjectInputFilter filter;
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   116
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    /** maps method hash to Method object for each remote method */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    private transient Map<Long,Method> hashToMethod_Map = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * A weak hash map, mapping classes to hash maps that map method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * hashes to method objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    private static final WeakClassHashMap<Map<Long,Method>> hashToMethod_Maps =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        new HashToMethod_Maps();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /** cache of impl classes that have no corresponding skeleton class */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private static final Map<Class<?>,?> withoutSkeletons =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Collections.synchronizedMap(new WeakHashMap<Class<?>,Void>());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   131
    private final AtomicInteger methodCallIDCount = new AtomicInteger(0);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   132
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Create a new (empty) Unicast server remote reference.
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   135
     * The filter is null to defer to the  default ObjectInputStream filter, if any.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    public UnicastServerRef() {
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   138
        this.filter = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Construct a Unicast server remote reference for a specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * liveRef.
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   144
     * The filter is null to defer to the  default ObjectInputStream filter, if any.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    public UnicastServerRef(LiveRef ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        super(ref);
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   148
        this.filter = null;
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   149
    }
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   150
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   151
    /**
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   152
     * Construct a Unicast server remote reference for a specified
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   153
     * liveRef and filter.
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   154
     */
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   155
    public UnicastServerRef(LiveRef ref, ObjectInputFilter filter) {
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   156
        super(ref);
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   157
        this.filter = filter;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Construct a Unicast server remote reference to be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * on the specified port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public UnicastServerRef(int port) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        super(new LiveRef(port));
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   166
        this.filter = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * Constructs a UnicastServerRef to be exported on an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * anonymous port (i.e., 0) and that uses a pregenerated stub class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * (NOT a dynamic proxy instance) if 'forceStubUse' is 'true'.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * This constructor is only called by the method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * UnicastRemoteObject.exportObject(Remote) passing 'true' for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * 'forceStubUse'.  The UnicastRemoteObject.exportObject(Remote) method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * returns RemoteStub, so it must ensure that the stub for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * exported object is an instance of a pregenerated stub class that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * extends RemoteStub (instead of an instance of a dynamic proxy class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * which is not an instance of RemoteStub).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    public UnicastServerRef(boolean forceStubUse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        this(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        this.forceStubUse = forceStubUse;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * With the addition of support for dynamic proxies as stubs, this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * method is obsolete because it returns RemoteStub instead of the more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * general Remote.  It should not be called.  It sets the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * 'forceStubUse' flag to true so that the stub for the exported object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * is forced to be an instance of the pregenerated stub class, which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * extends RemoteStub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * Export this object, create the skeleton and stubs for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * dispatcher.  Create a stub based on the type of the impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * initialize it with the appropriate remote reference. Create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * target defined by the impl, dispatcher (this) and stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Export that target via the Ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    public RemoteStub exportObject(Remote impl, Object data)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        forceStubUse = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        return (RemoteStub) exportObject(impl, data, false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * Export this object, create the skeleton and stubs for this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * dispatcher.  Create a stub based on the type of the impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * initialize it with the appropriate remote reference. Create the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * target defined by the impl, dispatcher (this) and stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * Export that target via the Ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public Remote exportObject(Remote impl, Object data,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                               boolean permanent)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        throws RemoteException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10912
diff changeset
   219
        Class<?> implClass = impl.getClass();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        Remote stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            stub = Util.createProxy(implClass, getClientRef(), forceStubUse);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            throw new ExportException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                "remote object implements illegal remote interface", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (stub instanceof RemoteStub) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            setSkeleton(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        Target target =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            new Target(impl, this, stub, ref.getObjID(), permanent);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        ref.exportObject(target);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        hashToMethod_Map = hashToMethod_Maps.get(implClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Return the hostname of the current client.  When called from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * thread actively handling a remote method invocation the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * hostname of the client is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * @exception ServerNotActiveException If called outside of servicing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * a remote method invocation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    public String getClientHost() throws ServerNotActiveException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        return TCPTransport.getClientHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * Discovers and sets the appropriate skeleton for the impl.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    public void setSkeleton(Remote impl) throws RemoteException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        if (!withoutSkeletons.containsKey(impl.getClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                skel = Util.createSkeleton(impl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            } catch (SkeletonNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                 * Ignore exception for skeleton class not found, because a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                 * skeleton class is not necessary with the 1.2 stub protocol.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                 * Remember that this impl's class does not have a skeleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                 * class so we don't waste time searching for it again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                withoutSkeletons.put(impl.getClass(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * Call to dispatch to the remote object (on the server side).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * The up-call to the server and the marshalling of return result
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * (or exception) should be handled before returning from this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * @param obj the target remote object for the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param call the "remote call" from which operation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * method arguments can be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @exception IOException If unable to marshal return result or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * release input or output streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    public void dispatch(Remote obj, RemoteCall call) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        // positive operation number in 1.1 stubs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        // negative version number in 1.2 stubs and beyond...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        int num;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        long op;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            // read remote call header
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            ObjectInput in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                in = call.getInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                num = in.readInt();
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   292
            } catch (Exception readEx) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   293
                throw new UnmarshalException("error unmarshalling call header",
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   294
                                             readEx);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   295
            }
54556
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   296
            if (skel != null) {
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   297
                // If there is a skeleton, use it
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   298
                    oldDispatch(obj, call, num);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   299
                    return;
54556
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   300
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   301
            } else if (num >= 0){
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   302
                throw new UnmarshalException(
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   303
                        "skeleton class not found but required for client version");
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   304
            }
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   305
            try {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                op = in.readLong();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            } catch (Exception readEx) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                throw new UnmarshalException("error unmarshalling call header",
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   309
                        readEx);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
             * Since only system classes (with null class loaders) will be on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
             * the execution stack during parameter unmarshalling for the 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
             * stub protocol, tell the MarshalInputStream not to bother trying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
             * to resolve classes using its superclasses's default method of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
             * consulting the first non-null class loader on the stack.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            MarshalInputStream marshalStream = (MarshalInputStream) in;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            marshalStream.skipDefaultResolveClass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            Method method = hashToMethod_Map.get(op);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                throw new UnmarshalException("unrecognized method hash: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                    "method not supported by remote object");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            // if calls are being logged, write out object id and operation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            logCall(obj, method);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            // unmarshal parameters
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   332
            Class<?>[] types = method.getParameterTypes();
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   333
            Object[] params = new Object[types.length];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
                unmarshalCustomCallData(in);
47425
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   337
                // Unmarshal the parameters
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   338
                for (int i = 0; i < types.length; i++) {
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   339
                    params[i] = unmarshalValue(types[i], in);
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   340
                }
96179f26139e 8187556: Backout of a fix reintroduced a dependency that had since been removed
jwilhelm
parents: 47216
diff changeset
   341
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   342
            } catch (AccessException aex) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   343
                // For compatibility, AccessException is not wrapped in UnmarshalException
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   344
                // disable saving any refs in the inputStream for GC
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   345
                ((StreamRemoteCall) call).discardPendingRefs();
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   346
                throw aex;
45984
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 41231
diff changeset
   347
            } catch (java.io.IOException | ClassNotFoundException e) {
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 41231
diff changeset
   348
                // disable saving any refs in the inputStream for GC
75fef64e21fa 8163958: Improved garbage collection
rriggs
parents: 41231
diff changeset
   349
                ((StreamRemoteCall) call).discardPendingRefs();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                throw new UnmarshalException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    "error unmarshalling arguments", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                call.releaseInputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // make upcall on remote object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            Object result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                result = method.invoke(obj, params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
            } catch (InvocationTargetException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                throw e.getTargetException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            // marshal return value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                ObjectOutput out = call.getResultStream(true);
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10912
diff changeset
   367
                Class<?> rtype = method.getReturnType();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                if (rtype != void.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    marshalValue(rtype, result, out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
            } catch (IOException ex) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                throw new MarshalException("error marshalling return", ex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                 * This throw is problematic because when it is caught below,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                 * we attempt to marshal it back to the client, but at this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                 * point, a "normal return" has already been indicated,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
                 * so marshalling an exception will corrupt the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
                 * This was the case with skeletons as well; there is no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                 * immediately obvious solution without a protocol change.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
                 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        } catch (Throwable e) {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   383
            Throwable origEx = e;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            logCallException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            ObjectOutput out = call.getResultStream(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            if (e instanceof Error) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                e = new ServerError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    "Error occurred in server thread", (Error) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            } else if (e instanceof RemoteException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                e = new ServerException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                    "RemoteException occurred in server thread",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                    (Exception) e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            if (suppressStackTraces) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                clearStackTraces(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            out.writeObject(e);
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   399
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   400
            // AccessExceptions should cause Transport.serviceCall
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   401
            // to flag the connection as unusable.
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   402
            if (origEx instanceof AccessException) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   403
                throw new IOException("Connection is not reusable", origEx);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   404
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            call.releaseInputStream(); // in case skeleton doesn't
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            call.releaseOutputStream();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   411
    /**
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   412
     * Sets a filter for invocation arguments, if a filter has been set.
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   413
     * Called by dispatch before the arguments are read.
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   414
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    protected void unmarshalCustomCallData(ObjectInput in)
41231
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   416
            throws IOException, ClassNotFoundException {
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   417
        if (filter != null &&
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   418
                in instanceof ObjectInputStream) {
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   419
            // Set the filter on the stream
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   420
            ObjectInputStream ois = (ObjectInputStream) in;
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   421
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   422
            AccessController.doPrivileged((PrivilegedAction<Void>)() -> {
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   423
                ois.setObjectInputFilter(filter);
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   424
                return null;
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   425
            });
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   426
        }
3f8807f6fec3 8165806: UnicastServerRef support to export an object with a filter
rriggs
parents: 37584
diff changeset
   427
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * Handle server-side dispatch using the RMI 1.1 stub/skeleton
54556
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   431
     * protocol, given a non-negative operation number or negative method hash
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   432
     * that has already been read from the call stream.
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   433
     * Exceptions are handled by the caller to be sent to the remote client.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @param obj the target remote object for the call
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @param call the "remote call" from which operation and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * method arguments can be obtained.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * @param op the operation number
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   439
     * @throws Exception if unable to marshal return result or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * release input or output streams
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   442
    private void oldDispatch(Remote obj, RemoteCall call, int op)
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   443
        throws Exception
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        long hash;              // hash for matching stub with skeleton
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   447
        // read remote call header
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   448
        ObjectInput in;
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   449
        in = call.getInputStream();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        try {
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   451
            Class<?> clazz = Class.forName("sun.rmi.transport.DGCImpl_Skel");
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   452
            if (clazz.isAssignableFrom(skel.getClass())) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   453
                ((MarshalInputStream)in).useCodebaseOnly();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            }
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   455
        } catch (ClassNotFoundException ignore) { }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   457
        try {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   458
            hash = in.readLong();
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   459
        } catch (Exception ioe) {
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   460
            throw new UnmarshalException("error unmarshalling call header", ioe);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   461
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   463
        // if calls are being logged, write out object id and operation
54556
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   464
        Operation[] operations = skel.getOperations();
30503c380394 8218453: More dynamic RMI interactions
rriggs
parents: 47425
diff changeset
   465
        logCall(obj, op >= 0 && op < operations.length ?  operations[op] : "op: " + op);
45989
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   466
        unmarshalCustomCallData(in);
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   467
        // dispatch to skeleton for remote object
e4f526fd8e09 8174770: Check registry registration location
rriggs
parents: 45984
diff changeset
   468
        skel.dispatch(obj, call, op, hash);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Clear the stack trace of the given Throwable by replacing it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * an empty StackTraceElement array, and do the same for all of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * chained causative exceptions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public static void clearStackTraces(Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        StackTraceElement[] empty = new StackTraceElement[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        while (t != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            t.setStackTrace(empty);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            t = t.getCause();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Log the details of an incoming call.  The method parameter is either of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * type java.lang.reflect.Method or java.rmi.server.Operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    private void logCall(Remote obj, Object method) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        if (callLog.isLoggable(Log.VERBOSE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            String clientHost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                clientHost = getClientHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            } catch (ServerNotActiveException snae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
                clientHost = "(local)"; // shouldn't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            callLog.log(Log.VERBOSE, "[" + clientHost + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                              obj.getClass().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                              ref.getObjID().toString() + ": " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                              method + "]");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Log the exception detail of an incoming call.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    private void logCallException(Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        // if calls are being logged, log them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        if (callLog.isLoggable(Log.BRIEF)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            String clientHost = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                clientHost = "[" + getClientHost() + "] ";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            } catch (ServerNotActiveException snae) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            callLog.log(Log.BRIEF, clientHost + "exception: ", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // write exceptions (only) to System.err if desired
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (wantExceptionLog) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            java.io.PrintStream log = System.err;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            synchronized (log) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                log.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                log.println("Exception dispatching call to " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                            ref.getObjID() + " in thread \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                            Thread.currentThread().getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                            "\" at " + (new Date()) + ":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                e.printStackTrace(log);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * Returns the class of the ref type to be serialized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    public String getRefClass(ObjectOutput out) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return "UnicastServerRef";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * Return the client remote reference for this remoteRef.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     * In the case of a client RemoteRef "this" is the answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * For a server remote reference, a client side one will have to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * found or created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    protected RemoteRef getClientRef() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        return new UnicastRef(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * Write out external representation for remote ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    public void writeExternal(ObjectOutput out) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     * Read in external representation for remote ref.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
     * @exception ClassNotFoundException If the class for an object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
     * being restored cannot be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    public void readExternal(ObjectInput in)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
        throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        // object is re-exported elsewhere (e.g., by UnicastRemoteObject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        ref = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
        skel = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
     * A weak hash map, mapping classes to hash maps that map method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * hashes to method objects.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
    private static class HashToMethod_Maps
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        extends WeakClassHashMap<Map<Long,Method>>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        HashToMethod_Maps() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
        protected Map<Long,Method> computeValue(Class<?> remoteClass) {
12040
558b0e0d5910 7146763: Warnings cleanup in the sun.rmi and related packages
khazra
parents: 10912
diff changeset
   578
            Map<Long,Method> map = new HashMap<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
            for (Class<?> cl = remoteClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
                 cl != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                 cl = cl.getSuperclass())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                for (Class<?> intf : cl.getInterfaces()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    if (Remote.class.isAssignableFrom(intf)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        for (Method method : intf.getMethods()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                            final Method m = method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                             * Set this Method object to override language
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                             * access checks so that the dispatcher can invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                             * methods from non-public remote interfaces.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                            AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                                new PrivilegedAction<Void>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                                public Void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                    m.setAccessible(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                                    return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                            map.put(Util.computeMethodHash(m), m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
            return map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
    }
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   607
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
}