changeset 4864:ef3503a5a3b9

Merge
author lana
date Wed, 07 Mar 2012 17:23:03 -0800
parents 00f0f18379ec ffdd6fa55445
children 67e66dee832b
files
diffstat 31 files changed, 1436 insertions(+), 214 deletions(-) [+]
line wrap: on
line diff
--- a/make/launchers/Makefile.launcher	Thu Mar 01 13:45:02 2012 -0800
+++ b/make/launchers/Makefile.launcher	Wed Mar 07 17:23:03 2012 -0800
@@ -159,8 +159,10 @@
 # GUI tools
 ifeq ($(GUI_TOOL),true)
   ifneq ($(PLATFORM), windows)
-    # Anything with a GUI needs X11 to be linked in.
-    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11
+    ifneq ($(PLATFORM), macosx)
+      # Anything with a GUI needs X11 to be linked in.
+      OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11
+    endif
   endif
 endif
 
--- a/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/com/apple/laf/AquaInternalFrameUI.java	Wed Mar 07 17:23:03 2012 -0800
@@ -257,7 +257,7 @@
     }
 
     public Dimension getPreferredSize(JComponent x) {
-        Dimension preferredSize = super.getMinimumSize(x);
+        Dimension preferredSize = super.getPreferredSize(x);
         Dimension minimumSize = frame.getMinimumSize();
         if (preferredSize.width < minimumSize.width) {
             preferredSize.width = minimumSize.width;
--- a/src/macosx/classes/com/apple/laf/AquaKeyBindings.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/com/apple/laf/AquaKeyBindings.java	Wed Mar 07 17:23:03 2012 -0800
@@ -142,6 +142,21 @@
         }));
     }
 
+    LateBoundInputMap getPasswordFieldInputMap() {
+        return new LateBoundInputMap(new SimpleBinding(getTextFieldInputMap().getBindings()),
+                // nullify all the bindings that may discover space characters in the text
+                new SimpleBinding(new String[] {
+                        "alt LEFT", null,
+                        "alt KP_LEFT", null,
+                        "alt RIGHT", null,
+                        "alt KP_RIGHT", null,
+                        "shift alt LEFT", null,
+                        "shift alt KP_LEFT", null,
+                        "shift alt RIGHT", null,
+                        "shift alt KP_RIGHT", null,
+                }));
+    }
+
     LateBoundInputMap getMultiLineTextInputMap() {
         return new LateBoundInputMap(new SimpleBinding(commonTextEditorBindings), new SimpleBinding(new String[] {
             "ENTER", DefaultEditorKit.insertBreakAction,
--- a/src/macosx/classes/com/apple/laf/AquaLookAndFeel.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/com/apple/laf/AquaLookAndFeel.java	Wed Mar 07 17:23:03 2012 -0800
@@ -691,7 +691,7 @@
             "Panel.foreground", black,
             "Panel.opaque", useOpaqueComponents,
 
-            "PasswordField.focusInputMap", aquaKeyBindings.getTextFieldInputMap(),
+            "PasswordField.focusInputMap", aquaKeyBindings.getPasswordFieldInputMap(),
             "PasswordField.font", controlFont,
             "PasswordField.background", textBackground,
             "PasswordField.foreground", textForeground,
--- a/src/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/com/apple/laf/AquaTabbedPaneUI.java	Wed Mar 07 17:23:03 2012 -0800
@@ -318,7 +318,7 @@
         }
 
         // not for the scrolling tabs
-        if (tabIndex >= 0) {
+        if (component == null && tabIndex >= 0) {
             paintTitle(g2d, font, metrics, textRect, tabIndex, title);
         }
 
--- a/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/sun/lwawt/LWComponentPeer.java	Wed Mar 07 17:23:03 2012 -0800
@@ -982,16 +982,23 @@
     // DropTargetPeer Method
     @Override
     public void addDropTarget(DropTarget dt) {
-        synchronized (dropTargetLock){
-            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
-            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
-            if (++fNumDropTargets == 1) {
-                // Having a non-null drop target would be an error but let's check just in case:
-                if (fDropTarget != null)
-                    System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
+        LWWindowPeer winPeer = getWindowPeerOrSelf();
+        if (winPeer != null && winPeer != this) {
+            // We need to register the DropTarget in the
+            // peer of the window ancestor of the component
+            winPeer.addDropTarget(dt);
+        } else {
+            synchronized (dropTargetLock) {
+                // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
+                // if it's the first (or last) one for the component. Otherwise this call is a no-op.
+                if (++fNumDropTargets == 1) {
+                    // Having a non-null drop target would be an error but let's check just in case:
+                    if (fDropTarget != null)
+                        System.err.println("CComponent.addDropTarget(): current drop target is non-null.");
 
-                // Create a new drop target:
-                fDropTarget = CDropTarget.createDropTarget(dt, target, this);
+                    // Create a new drop target:
+                    fDropTarget = CDropTarget.createDropTarget(dt, target, this);
+                }
             }
         }
     }
@@ -999,17 +1006,24 @@
     // DropTargetPeer Method
     @Override
     public void removeDropTarget(DropTarget dt) {
-        synchronized (dropTargetLock){
-            // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
-            // if it's the first (or last) one for the component. Otherwise this call is a no-op.
-            if (--fNumDropTargets == 0) {
-                // Having a null drop target would be an error but let's check just in case:
-                if (fDropTarget != null) {
-                    // Dispose of the drop target:
-                    fDropTarget.dispose();
-                    fDropTarget = null;
-                } else
-                    System.err.println("CComponent.removeDropTarget(): current drop target is null.");
+        LWWindowPeer winPeer = getWindowPeerOrSelf();
+        if (winPeer != null && winPeer != this) {
+            // We need to unregister the DropTarget in the
+            // peer of the window ancestor of the component
+            winPeer.removeDropTarget(dt);
+        } else {
+            synchronized (dropTargetLock){
+                // 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only
+                // if it's the first (or last) one for the component. Otherwise this call is a no-op.
+                if (--fNumDropTargets == 0) {
+                    // Having a null drop target would be an error but let's check just in case:
+                    if (fDropTarget != null) {
+                        // Dispose of the drop target:
+                        fDropTarget.dispose();
+                        fDropTarget = null;
+                    } else
+                        System.err.println("CComponent.removeDropTarget(): current drop target is null.");
+                }
             }
         }
     }
@@ -1114,7 +1128,7 @@
         sendEventToDelegate(e);
     }
 
-    private void sendEventToDelegate(final AWTEvent e) {
+    protected void sendEventToDelegate(final AWTEvent e) {
         synchronized (getDelegateLock()) {
             if (getDelegate() == null || !isShowing() || !isEnabled()) {
                 return;
--- a/src/macosx/classes/sun/lwawt/LWScrollPanePeer.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/sun/lwawt/LWScrollPanePeer.java	Wed Mar 07 17:23:03 2012 -0800
@@ -29,6 +29,7 @@
 import javax.swing.event.ChangeListener;
 import javax.swing.event.ChangeEvent;
 import java.awt.*;
+import java.awt.event.MouseWheelEvent;
 import java.awt.peer.ScrollPanePeer;
 import java.util.List;
 
@@ -52,6 +53,21 @@
     }
 
     @Override
+    public void handleEvent(AWTEvent e) {
+        if (e instanceof MouseWheelEvent) {
+            MouseWheelEvent wheelEvent = (MouseWheelEvent) e;
+            //java.awt.ScrollPane consumes the event
+            // in case isWheelScrollingEnabled() is true,
+            // forcibly send the consumed event to the delegate
+            if (getTarget().isWheelScrollingEnabled() && wheelEvent.isConsumed()) {
+                sendEventToDelegate(wheelEvent);
+            }
+        } else {
+            super.handleEvent(e);
+        }
+    }
+
+    @Override
     public void stateChanged(final ChangeEvent e) {
         SwingUtilities.invokeLater(new Runnable() {
             @Override
--- a/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Wed Mar 07 17:23:03 2012 -0800
@@ -34,7 +34,7 @@
 import java.awt.event.FocusEvent;
 import java.awt.peer.TextFieldPeer;
 
-import javax.swing.JPasswordField;
+import javax.swing.*;
 import javax.swing.text.JTextComponent;
 
 final class LWTextFieldPeer
@@ -50,7 +50,7 @@
 
     @Override
     protected JPasswordField createDelegate() {
-        return new JTextAreaDelegate();
+        return new JPasswordFieldDelegate();
     }
 
     @Override
@@ -71,9 +71,18 @@
     public void setEchoChar(final char echoChar) {
         synchronized (getDelegateLock()) {
             getDelegate().setEchoChar(echoChar);
-            getDelegate().putClientProperty("JPasswordField.cutCopyAllowed",
-                                            getDelegate().echoCharIsSet()
-                                            ? Boolean.FALSE : Boolean.TRUE);
+            final boolean cutCopyAllowed;
+            final String focusInputMapKey;
+            if (echoChar != 0) {
+                cutCopyAllowed = false;
+                focusInputMapKey = "PasswordField.focusInputMap";
+            } else {
+                cutCopyAllowed = true;
+                focusInputMapKey = "TextField.focusInputMap";
+            }
+            getDelegate().putClientProperty("JPasswordField.cutCopyAllowed", cutCopyAllowed);
+            InputMap inputMap = (InputMap) UIManager.get(focusInputMapKey);
+            SwingUtilities.replaceUIInputMap(getDelegate(), JComponent.WHEN_FOCUSED, inputMap);
         }
     }
 
@@ -113,11 +122,11 @@
         super.handleJavaFocusEvent(e);
     }
 
-    private final class JTextAreaDelegate extends JPasswordField {
+    private final class JPasswordFieldDelegate extends JPasswordField {
 
         // Empty non private constructor was added because access to this
         // class shouldn't be emulated by a synthetic accessor method.
-        JTextAreaDelegate() {
+        JPasswordFieldDelegate() {
             super();
         }
 
--- a/src/macosx/native/sun/awt/CDropTarget.m	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/native/sun/awt/CDropTarget.m	Wed Mar 07 17:23:03 2012 -0800
@@ -648,6 +648,10 @@
     if (sDraggingError == FALSE) {
         sDraggingLocation = [sender draggingLocation];
         NSPoint javaLocation = [fView convertPoint:sDraggingLocation fromView:nil];
+        // The y coordinate that comes in the NSDraggingInfo seems to be reversed - probably
+        // has to do something with the type of view it comes to.
+        // This is the earliest place where we can correct it.
+        javaLocation.y = fView.window.frame.size.height - javaLocation.y;
 
         jint actions = [DnDUtilities mapNSDragOperationMaskToJava:[sender draggingSourceOperationMask]];
         jint dropAction = sJavaDropOperation;
--- a/src/macosx/native/sun/awt/CFileDialog.m	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/native/sun/awt/CFileDialog.m	Wed Mar 07 17:23:03 2012 -0800
@@ -117,13 +117,15 @@
         fPanelResult = [thePanel runModalForDirectory:fDirectory file:fFile];
         [thePanel setDelegate:nil];
 
-        if (fMode == java_awt_FileDialog_LOAD) {
-            NSOpenPanel *openPanel = (NSOpenPanel *)thePanel;
-            fURLs = [openPanel URLs];
-        } else {
-            fURLs = [NSArray arrayWithObject:[thePanel URL]];
+        if ([self userClickedOK]) {
+            if (fMode == java_awt_FileDialog_LOAD) {
+                NSOpenPanel *openPanel = (NSOpenPanel *)thePanel;
+                fURLs = [openPanel URLs];
+            } else {
+                fURLs = [NSArray arrayWithObject:[thePanel URL]];
+            }
+            [fURLs retain];
         }
-        [fURLs retain];
     }
 
     [self disposer];
@@ -213,12 +215,11 @@
         returnValue = (*env)->NewObjectArray(env, count, stringClass, NULL);
         (*env)->DeleteLocalRef(env, stringClass);
 
-        NSUInteger i;
-        for (i = 0; i < count; i++) {
-            jstring filename = JNFNSToJavaString(env, [[urls objectAtIndex:i] absoluteString]);
-            (*env)->SetObjectArrayElement(env, returnValue, i, filename);
+        [urls enumerateObjectsUsingBlock:^(id url, NSUInteger index, BOOL *stop) {
+            jstring filename = JNFNormalizedJavaStringForPath(env, [url path]);
+            (*env)->SetObjectArrayElement(env, returnValue, index, filename);
             (*env)->DeleteLocalRef(env, filename);
-        }
+        }];
     }
 
     [dialogDelegate release];
--- a/src/macosx/native/sun/awt/awt.m	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/macosx/native/sun/awt/awt.m	Wed Mar 07 17:23:03 2012 -0800
@@ -306,6 +306,18 @@
         // AWT gets here AFTER +[AWTStarter appKitIsRunning:] is called.
         if (verbose) AWT_DEBUG_LOG(@"got out of the AppKit startup mutex");
     }
+
+    // Don't set the delegate until the NSApplication has been created and
+    // its finishLaunching has initialized it.
+    //  ApplicationDelegate is the support code for com.apple.eawt.
+    void (^setDelegateBlock)() = ^(){
+        OSXAPP_SetApplicationDelegate([ApplicationDelegate sharedDelegate]);
+    };
+    if (onMainThread) {
+        setDelegateBlock();
+    } else {
+        [JNFRunLoop performOnMainThreadWaiting:YES withBlock:setDelegateBlock];
+    }
 }
 
 - (void)starter:(NSArray*)args {
@@ -340,10 +352,6 @@
     //  AppKit Application.
     NSApplication *app = [NSApplicationAWT sharedApplication];
 
-    // Don't set the delegate until the NSApplication has been created.
-    //  ApplicationDelegate is the support code for com.apple.eawt.
-    OSXAPP_SetApplicationDelegate([ApplicationDelegate sharedDelegate]);
-
     // AWT gets to this point BEFORE NSApplicationDidFinishLaunchingNotification is sent.
     if (![app isRunning]) {
         if (verbose) AWT_DEBUG_LOG(@"+[AWTStarter startAWT]: ![app isRunning]");
--- a/src/share/classes/java/awt/Component.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/java/awt/Component.java	Wed Mar 07 17:23:03 2012 -0800
@@ -10072,11 +10072,12 @@
         }
         Window window = getContainingWindow();
         if (window != null) {
-            if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants()) {
+            if (!window.hasHeavyweightDescendants() || !window.hasLightweightDescendants() || window.isDisposing()) {
                 if (mixingLog.isLoggable(PlatformLogger.FINE)) {
                     mixingLog.fine("containing window = " + window +
                             "; has h/w descendants = " + window.hasHeavyweightDescendants() +
-                            "; has l/w descendants = " + window.hasLightweightDescendants());
+                            "; has l/w descendants = " + window.hasLightweightDescendants() +
+                            "; disposing = " + window.isDisposing());
                 }
                 return false;
             }
--- a/src/share/classes/java/awt/Window.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/java/awt/Window.java	Wed Mar 07 17:23:03 2012 -0800
@@ -226,6 +226,7 @@
     static boolean systemSyncLWRequests = false;
     boolean     syncLWRequests = false;
     transient boolean beforeFirstShow = true;
+    private transient boolean disposing = false;
 
     static final int OPENED = 0x01;
 
@@ -1162,36 +1163,41 @@
     void doDispose() {
     class DisposeAction implements Runnable {
         public void run() {
-            // Check if this window is the fullscreen window for the
-            // device. Exit the fullscreen mode prior to disposing
-            // of the window if that's the case.
-            GraphicsDevice gd = getGraphicsConfiguration().getDevice();
-            if (gd.getFullScreenWindow() == Window.this) {
-                gd.setFullScreenWindow(null);
+            disposing = true;
+            try {
+                // Check if this window is the fullscreen window for the
+                // device. Exit the fullscreen mode prior to disposing
+                // of the window if that's the case.
+                GraphicsDevice gd = getGraphicsConfiguration().getDevice();
+                if (gd.getFullScreenWindow() == Window.this) {
+                    gd.setFullScreenWindow(null);
+                }
+
+                Object[] ownedWindowArray;
+                synchronized(ownedWindowList) {
+                    ownedWindowArray = new Object[ownedWindowList.size()];
+                    ownedWindowList.copyInto(ownedWindowArray);
+                }
+                for (int i = 0; i < ownedWindowArray.length; i++) {
+                    Window child = (Window) (((WeakReference)
+                                   (ownedWindowArray[i])).get());
+                    if (child != null) {
+                        child.disposeImpl();
+                    }
+                }
+                hide();
+                beforeFirstShow = true;
+                removeNotify();
+                synchronized (inputContextLock) {
+                    if (inputContext != null) {
+                        inputContext.dispose();
+                        inputContext = null;
+                    }
+                }
+                clearCurrentFocusCycleRootOnHide();
+            } finally {
+                disposing = false;
             }
-
-            Object[] ownedWindowArray;
-            synchronized(ownedWindowList) {
-                ownedWindowArray = new Object[ownedWindowList.size()];
-                ownedWindowList.copyInto(ownedWindowArray);
-            }
-            for (int i = 0; i < ownedWindowArray.length; i++) {
-                Window child = (Window) (((WeakReference)
-                               (ownedWindowArray[i])).get());
-                if (child != null) {
-                    child.disposeImpl();
-                }
-            }
-            hide();
-            beforeFirstShow = true;
-            removeNotify();
-            synchronized (inputContextLock) {
-                if (inputContext != null) {
-                    inputContext.dispose();
-                    inputContext = null;
-                }
-            }
-            clearCurrentFocusCycleRootOnHide();
         }
     }
         DisposeAction action = new DisposeAction();
@@ -2734,6 +2740,10 @@
         return visible;
     }
 
+    boolean isDisposing() {
+        return disposing;
+    }
+
     /**
      * @deprecated As of J2SE 1.4, replaced by
      * {@link Component#applyComponentOrientation Component.applyComponentOrientation}.
--- a/src/share/classes/javax/swing/JViewport.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/javax/swing/JViewport.java	Wed Mar 07 17:23:03 2012 -0800
@@ -27,9 +27,7 @@
 
 import java.awt.*;
 import java.awt.event.*;
-import java.awt.image.VolatileImage;
 import java.awt.peer.ComponentPeer;
-import java.applet.Applet;
 import java.beans.Transient;
 import javax.swing.plaf.ViewportUI;
 
@@ -265,6 +263,14 @@
      */
     private boolean hasHadValidView;
 
+    /**
+     * When view is changed we have to synchronize scrollbar values
+     * with viewport (see the BasicScrollPaneUI#syncScrollPaneWithViewport method).
+     * This flag allows to invoke that method while ScrollPaneLayout#layoutContainer
+     * is running.
+     */
+    private boolean viewChanged;
+
     /** Creates a <code>JViewport</code>. */
     public JViewport() {
         super();
@@ -830,7 +836,9 @@
             backingStoreImage = null;
         }
         super.reshape(x, y, w, h);
-        if (sizeChanged) {
+        if (sizeChanged || viewChanged) {
+            viewChanged = false;
+
             fireStateChanged();
         }
     }
@@ -967,6 +975,8 @@
             hasHadValidView = true;
         }
 
+        viewChanged = true;
+
         revalidate();
         repaint();
     }
--- a/src/share/classes/sun/management/Agent.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/sun/management/Agent.java	Wed Mar 07 17:23:03 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -25,30 +25,34 @@
 
 package sun.management;
 
+import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.InputStream;
 import java.io.FileInputStream;
-import java.io.BufferedInputStream;
 import java.io.FileNotFoundException;
 import java.io.IOException;
+import java.io.InputStream;
+
 import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.management.ManagementFactory;
+
 import java.text.MessageFormat;
+
+import java.util.MissingResourceException;
 import java.util.Properties;
 import java.util.ResourceBundle;
-import java.util.MissingResourceException;
-import java.lang.management.ManagementFactory;
-import java.lang.reflect.Method;
 
 import javax.management.remote.JMXConnectorServer;
 
+import static sun.management.AgentConfigurationError.*;
 import sun.management.jmxremote.ConnectorBootstrap;
-import static sun.management.AgentConfigurationError.*;
 import sun.misc.VMSupport;
 
 /**
  * This Agent is started by the VM when -Dcom.sun.management.snmp
  * or -Dcom.sun.management.jmxremote is set. This class will be
- * loaded by the system class loader.
+ * loaded by the system class loader. Also jmx framework could
+ * be started by jcmd
  */
 public class Agent {
     // management properties
@@ -69,7 +73,33 @@
         "com.sun.management.jmxremote.localConnectorAddress";
 
     private static final String SNMP_ADAPTOR_BOOTSTRAP_CLASS_NAME =
-            "sun.management.snmp.AdaptorBootstrap";
+        "sun.management.snmp.AdaptorBootstrap";
+
+    // The only active agent allowed
+    private static JMXConnectorServer jmxServer = null;
+
+    // Parse string com.sun.management.prop=xxx,com.sun.management.prop=yyyy
+    // and return property set if args is null or empty
+    // return empty property set
+    private static Properties parseString(String args){
+        Properties argProps = new Properties();
+        if (args != null) {
+           for (String option : args.split(",")) {
+               String s[] = option.split("=", 2);
+               String name = s[0].trim();
+               String value = (s.length > 1) ? s[1].trim() : "";
+
+               if (!name.startsWith("com.sun.management.")) {
+                  error(INVALID_OPTION, name);
+               }
+
+               argProps.setProperty(name, value);
+           }
+        }
+
+        return argProps;
+    }
+
 
     // invoked by -javaagent or -Dcom.sun.management.agent.class
     public static void premain(String args) throws Exception {
@@ -82,37 +112,104 @@
             args = JMXREMOTE;           // default to local management
         }
 
-        // Parse agent options into properties
+        Properties arg_props = parseString(args);
 
-        Properties arg_props = new Properties();
-        if (args != null) {
-            String[] options = args.split(",");
-            for (int i=0; i<options.length; i++) {
-                String[] option = options[i].split("=");
-                if (option.length >= 1 && option.length <= 2) {
-                    String name = option[0];
-                    String value = (option.length == 1) ? "" : option[1];
-                    if (name != null && name.length() > 0) {
+        // Read properties from the config file
+         Properties config_props = new Properties();
+         String fname = arg_props.getProperty(CONFIG_FILE);
+         readConfiguration(fname, config_props);
 
-                        // Assume that any com.sun.management.* options are okay
-                        if (name.startsWith("com.sun.management.")) {
-                            arg_props.setProperty(name, value);
-                        } else {
-                            error(INVALID_OPTION, name);
-                        }
-                    }
-                }
+         // Arguments override config file
+         config_props.putAll(arg_props);
+         startAgent(config_props);
+    }
+
+    // jcmd ManagementAgent.start_local entry point
+    // Also called due to command-line via startAgent()
+    private static synchronized void startLocalManagementAgent(){
+        Properties agentProps = VMSupport.getAgentProperties();
+
+        // start local connector if not started
+        if (agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP) == null) {
+            JMXConnectorServer cs = ConnectorBootstrap.startLocalConnectorServer();
+            String address = cs.getAddress().toString();
+            // Add the local connector address to the agent properties
+            agentProps.put(LOCAL_CONNECTOR_ADDRESS_PROP, address);
+
+            try {
+                // export the address to the instrumentation buffer
+                ConnectorAddressLink.export(address);
+            } catch (Exception x) {
+                // Connector server started but unable to export address
+                // to instrumentation buffer - non-fatal error.
+                warning(EXPORT_ADDRESS_FAILED, x.getMessage());
             }
         }
+    }
 
-        // Read properties from the config file
-        Properties config_props = new Properties();
-        String fname = arg_props.getProperty(CONFIG_FILE);
-        readConfiguration(fname, config_props);
+    // jcmd ManagementAgent.start entry point
+    // This method starts the remote JMX agent and starts neither
+    // the local JMX agent nor the SNMP agent
+    // @see #startLocalManagementAgent and also @see #startAgent.
+    private static synchronized void startRemoteManagementAgent(String args) throws Exception {
+        if (jmxServer != null) {
+            throw new RuntimeException(getText(INVALID_STATE, "Agent already started"));
+        }
 
-        // Arguments override config file
-        config_props.putAll(arg_props);
-        startAgent(config_props);
+        Properties argProps    = parseString(args);
+        Properties configProps = new Properties();
+
+        // Load the management properties from the config file
+        // if config file is not specified readConfiguration implicitly
+        // reads <java.home>/lib/management/management.properties
+
+        String fname = System.getProperty(CONFIG_FILE);
+        readConfiguration(fname, configProps);
+
+        // management properties can be overridden by system properties
+        // which take precedence
+        configProps.putAll(System.getProperties());
+
+        // if user specifies config file into command line for either
+        // jcmd utilities or attach command it overrides properties set in
+        // command line at the time of VM start
+        String fnameUser = argProps.getProperty(CONFIG_FILE);
+        if (fnameUser != null) {
+            readConfiguration(fnameUser, configProps);
+        }
+
+        // arguments specified in command line of jcmd utilities
+        // override both system properties and one set by config file
+        // specified in jcmd command line
+        configProps.putAll(argProps);
+
+        // jcmd doesn't allow to change ThreadContentionMonitoring, but user
+        // can specify this property inside config file, so enable optional
+        // monitoring functionality if this property is set
+        final String enableThreadContentionMonitoring =
+            configProps.getProperty(ENABLE_THREAD_CONTENTION_MONITORING);
+
+        if (enableThreadContentionMonitoring != null) {
+            ManagementFactory.getThreadMXBean().
+                setThreadContentionMonitoringEnabled(true);
+        }
+
+        String jmxremotePort = configProps.getProperty(JMXREMOTE_PORT);
+        if (jmxremotePort != null) {
+            jmxServer = ConnectorBootstrap.
+                           startRemoteConnectorServer(jmxremotePort, configProps);
+        }
+    }
+
+    private static synchronized void stopRemoteManagementAgent() throws Exception {
+        if (jmxServer != null) {
+            ConnectorBootstrap.unexportRegistry();
+
+            // Attempt to stop already stopped agent
+            // Don't cause any errors.
+            jmxServer.stop();
+            jmxServer = null;
+        }
     }
 
     private static void startAgent(Properties props) throws Exception {
@@ -130,7 +227,7 @@
 
         try {
             if (snmpPort != null) {
-                loadSnmpAgent(snmpPort, props);
+               loadSnmpAgent(snmpPort, props);
             }
 
             /*
@@ -142,31 +239,14 @@
              * of this "local" server is exported as a counter to the jstat
              * instrumentation buffer.
              */
-            if (jmxremote != null || jmxremotePort != null) {
+             if (jmxremote != null || jmxremotePort != null) {
                 if (jmxremotePort != null) {
-                    ConnectorBootstrap.initialize(jmxremotePort, props);
+                   jmxServer = ConnectorBootstrap.
+                               startRemoteConnectorServer(jmxremotePort, props);
                 }
+                startLocalManagementAgent();
+             }
 
-                Properties agentProps = VMSupport.getAgentProperties();
-                // start local connector if not started
-                // System.out.println("local address : " +
-                  //     agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP));
-                if (agentProps.get(LOCAL_CONNECTOR_ADDRESS_PROP) == null) {
-                    JMXConnectorServer cs = ConnectorBootstrap.startLocalConnectorServer();
-                    String address = cs.getAddress().toString();
-                    // Add the local connector address to the agent properties
-                    agentProps.put(LOCAL_CONNECTOR_ADDRESS_PROP, address);
-
-                    try {
-                        // export the address to the instrumentation buffer
-                        ConnectorAddressLink.export(address);
-                    } catch (Exception x) {
-                        // Connector server started but unable to export address
-                        // to instrumentation buffer - non-fatal error.
-                        warning(EXPORT_ADDRESS_FAILED, x.getMessage());
-                    }
-                }
-            }
         } catch (AgentConfigurationError e) {
             error(e.getError(), e.getParams());
         } catch (Exception e) {
@@ -187,9 +267,9 @@
         props.putAll(System.getProperties());
 
         return props;
-    }
+   }
 
-    public static synchronized Properties getManagementProperties() {
+   public static synchronized Properties getManagementProperties() {
         if (mgmtProps == null) {
             String configFile = System.getProperty(CONFIG_FILE);
             String snmpPort = System.getProperty(SNMP_PORT);
--- a/src/share/classes/sun/management/AgentConfigurationError.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/sun/management/AgentConfigurationError.java	Wed Mar 07 17:23:03 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -53,6 +53,8 @@
         "agent.err.invalid.agentclass";
     public static final String INVALID_JMXREMOTE_PORT =
         "agent.err.invalid.jmxremote.port";
+    public static final String INVALID_JMXREMOTE_RMI_PORT =
+        "agent.err.invalid.jmxremote.rmi.port";
     public static final String PASSWORD_FILE_NOT_SET =
         "agent.err.password.file.notset";
     public static final String PASSWORD_FILE_NOT_READABLE =
@@ -105,6 +107,8 @@
         "agent.err.snmp.adaptor.start.failed";
     public static final String SNMP_MIB_INIT_FAILED =
         "agent.err.snmp.mib.init.failed";
+    public static final String INVALID_STATE =
+        "agent.err.invalid.state";
 
     private final String error;
     private final String[] params;
--- a/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/sun/management/jmxremote/ConnectorBootstrap.java	Wed Mar 07 17:23:03 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -28,25 +28,22 @@
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
+import java.io.IOException;
 import java.io.InputStream;
-import java.io.IOException;
-
+import java.lang.management.ManagementFactory;
 import java.net.InetAddress;
 import java.net.MalformedURLException;
 import java.net.UnknownHostException;
-
 import java.rmi.NoSuchObjectException;
 import java.rmi.Remote;
 import java.rmi.RemoteException;
 import java.rmi.registry.Registry;
-import java.rmi.server.RemoteObject;
 import java.rmi.server.RMIClientSocketFactory;
 import java.rmi.server.RMIServerSocketFactory;
+import java.rmi.server.RemoteObject;
 import java.rmi.server.UnicastRemoteObject;
-
 import java.security.KeyStore;
 import java.security.Principal;
-
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -55,35 +52,31 @@
 import java.util.Set;
 import java.util.StringTokenizer;
 
-import java.lang.management.ManagementFactory;
-
-import javax.net.ssl.*;
-
 import javax.management.MBeanServer;
 import javax.management.remote.JMXAuthenticator;
 import javax.management.remote.JMXConnectorServer;
 import javax.management.remote.JMXConnectorServerFactory;
 import javax.management.remote.JMXServiceURL;
 import javax.management.remote.rmi.RMIConnectorServer;
-
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.SSLContext;
+import javax.net.ssl.TrustManagerFactory;
 import javax.rmi.ssl.SslRMIClientSocketFactory;
 import javax.rmi.ssl.SslRMIServerSocketFactory;
-
 import javax.security.auth.Subject;
 
-import sun.rmi.server.UnicastRef;
-import sun.rmi.server.UnicastServerRef;
-import sun.rmi.server.UnicastServerRef2;
+import com.sun.jmx.remote.internal.RMIExporter;
+import com.sun.jmx.remote.security.JMXPluggableAuthenticator;
+import com.sun.jmx.remote.util.ClassLogger;
 
 import sun.management.Agent;
 import sun.management.AgentConfigurationError;
 import static sun.management.AgentConfigurationError.*;
 import sun.management.ConnectorAddressLink;
 import sun.management.FileSystem;
-import com.sun.jmx.remote.util.ClassLogger;
-
-import com.sun.jmx.remote.internal.RMIExporter;
-import com.sun.jmx.remote.security.JMXPluggableAuthenticator;
+import sun.rmi.server.UnicastRef;
+import sun.rmi.server.UnicastServerRef;
+import sun.rmi.server.UnicastServerRef2;
 
 /**
  * This class initializes and starts the RMIConnectorServer for JSR 163
@@ -114,6 +107,8 @@
 
         public static final String PORT =
                 "com.sun.management.jmxremote.port";
+        public static final String RMI_PORT =
+                "com.sun.management.jmxremote.rmi.port";
         public static final String CONFIG_FILE_NAME =
                 "com.sun.management.config.file";
         public static final String USE_LOCAL_ONLY =
@@ -267,34 +262,61 @@
         private final String accessFile;
     }
 
+    // The variable below is here to support stop functionality
+    // It would be overriten if you call startRemoteCommectionServer second
+    // time. It's OK for now as logic in Agent.java forbids mutiple agents
+    private static Registry registry = null;
+
+    public static void unexportRegistry() {
+        // Remove the entry from registry
+        try {
+            if (registry != null) {
+                UnicastRemoteObject.unexportObject(registry, true);
+                registry = null;
+            }
+        } catch(NoSuchObjectException ex) {
+            // This exception can appears only if we attempt
+            // to unexportRegistry second time. So it's safe
+            // to ignore it without additional messages.
+        }
+    }
+
+     /**
+      * Initializes and starts the JMX Connector Server.
+      * If the com.sun.management.jmxremote.port property is not defined,
+      * simply return. Otherwise, attempts to load the config file, and
+      * then calls {@link #startRemoteConnectorServer
+      *                            (java.lang.String, java.util.Properties)}.
+      *
+      * This method is used by some jtreg tests.
+      **/
+      public static synchronized JMXConnectorServer initialize() {
+
+         // Load a new management properties
+         final Properties props = Agent.loadManagementProperties();
+         if (props == null) {
+              return null;
+         }
+
+         final String portStr = props.getProperty(PropertyNames.PORT);
+         return startRemoteConnectorServer(portStr, props);
+     }
+
     /**
-     * Initializes and starts the JMX Connector Server.
-     * If the com.sun.management.jmxremote.port property is not defined,
-     * simply return. Otherwise, attempts to load the config file, and
-     * then calls {@link #initialize(java.lang.String, java.util.Properties)}.
+     * This method is used by some jtreg tests.
      *
-     **/
-    public static synchronized JMXConnectorServer initialize() {
-
-        // Load a new management properties
-        final Properties props = Agent.loadManagementProperties();
-        if (props == null) {
-            return null;
-        }
-
-        final String portStr = props.getProperty(PropertyNames.PORT);
-
-
-        // System.out.println("initializing: {port=" + portStr + ",
-        //                     properties="+props+"}");
-        return initialize(portStr, props);
+     * @see #startRemoteConnectorServer
+     *             (String portStr, Properties props)
+     */
+    public static synchronized JMXConnectorServer initialize(String portStr, Properties props)  {
+         return startRemoteConnectorServer(portStr, props);
     }
 
     /**
      * Initializes and starts a JMX Connector Server for remote
      * monitoring and management.
      **/
-    public static synchronized JMXConnectorServer initialize(String portStr, Properties props) {
+    public static synchronized JMXConnectorServer startRemoteConnectorServer(String portStr, Properties props) {
 
         // Get port number
         final int port;
@@ -307,6 +329,22 @@
             throw new AgentConfigurationError(INVALID_JMXREMOTE_PORT, portStr);
         }
 
+        // User can specify a port to be used to export rmi object,
+        // in order to simplify firewall rules
+        // if port is not specified random one will be allocated.
+        int rmiPort = 0;
+        String rmiPortStr = props.getProperty(PropertyNames.RMI_PORT);
+        try {
+            if (rmiPortStr != null) {
+               rmiPort = Integer.parseInt(rmiPortStr);
+            }
+        } catch (NumberFormatException x) {
+            throw new AgentConfigurationError(INVALID_JMXREMOTE_RMI_PORT, x, rmiPortStr);
+        }
+        if (rmiPort < 0) {
+            throw new AgentConfigurationError(INVALID_JMXREMOTE_RMI_PORT, rmiPortStr);
+        }
+
         // Do we use authentication?
         final String useAuthenticationStr =
                 props.getProperty(PropertyNames.USE_AUTHENTICATION,
@@ -388,9 +426,10 @@
         }
 
         if (log.debugOn()) {
-            log.debug("initialize",
-                    Agent.getText("jmxremote.ConnectorBootstrap.initialize") +
+            log.debug("startRemoteConnectorServer",
+                    Agent.getText("jmxremote.ConnectorBootstrap.starting") +
                     "\n\t" + PropertyNames.PORT + "=" + port +
+                    "\n\t" + PropertyNames.RMI_PORT + "=" + rmiPort +
                     "\n\t" + PropertyNames.USE_SSL + "=" + useSsl +
                     "\n\t" + PropertyNames.USE_REGISTRY_SSL + "=" + useRegistrySsl +
                     "\n\t" + PropertyNames.SSL_CONFIG_FILE_NAME + "=" + sslConfigFileName +
@@ -405,7 +444,7 @@
                     (useAuthentication ? (loginConfigName == null ? ("\n\t" + PropertyNames.PASSWORD_FILE_NAME + "=" +
                     passwordFileName) : ("\n\t" + PropertyNames.LOGIN_CONFIG_NAME + "=" +
                     loginConfigName)) : "\n\t" +
-                    Agent.getText("jmxremote.ConnectorBootstrap.initialize.noAuthentication")) +
+                    Agent.getText("jmxremote.ConnectorBootstrap.noAuthentication")) +
                     (useAuthentication ? ("\n\t" + PropertyNames.ACCESS_FILE_NAME + "=" +
                     accessFileName) : "") +
                     "");
@@ -416,15 +455,15 @@
         JMXServiceURL url = null;
         try {
             final JMXConnectorServerData data = exportMBeanServer(
-                    mbs, port, useSsl, useRegistrySsl,
+                    mbs, port, rmiPort, useSsl, useRegistrySsl,
                     sslConfigFileName, enabledCipherSuitesList,
                     enabledProtocolsList, sslNeedClientAuth,
                     useAuthentication, loginConfigName,
                     passwordFileName, accessFileName);
             cs = data.jmxConnectorServer;
             url = data.jmxRemoteURL;
-            log.config("initialize",
-                    Agent.getText("jmxremote.ConnectorBootstrap.initialize.ready",
+            log.config("startRemoteConnectorServer",
+                    Agent.getText("jmxremote.ConnectorBootstrap.ready",
                     url.toString()));
         } catch (Exception e) {
             throw new AgentConfigurationError(AGENT_EXCEPTION, e, e.toString());
@@ -443,7 +482,7 @@
             // Remote connector server started but unable to export remote
             // connector address and associated configuration properties to
             // the instrumentation buffer - non-fatal error.
-            log.debug("initialize", e);
+            log.debug("startRemoteConnectorServer", e);
         }
         return cs;
     }
@@ -518,9 +557,9 @@
         try {
             if (fs.supportsFileSecurity(file)) {
                 if (!fs.isAccessUserOnly(file)) {
-                    final String msg = Agent.getText("jmxremote.ConnectorBootstrap.initialize.password.readonly",
+                    final String msg = Agent.getText("jmxremote.ConnectorBootstrap.password.readonly",
                             passwordFileName);
-                    log.config("initialize", msg);
+                    log.config("startRemoteConnectorServer", msg);
                     throw new AgentConfigurationError(PASSWORD_FILE_ACCESS_NOT_RESTRICTED,
                             passwordFileName);
                 }
@@ -561,9 +600,9 @@
             if (fs.supportsFileSecurity(file)) {
                 if (!fs.isAccessUserOnly(file)) {
                     final String msg = Agent.getText(
-                            "jmxremote.ConnectorBootstrap.initialize.file.readonly",
+                            "jmxremote.ConnectorBootstrap.file.readonly",
                             restrictedFileName);
-                    log.config("initialize", msg);
+                    log.config("startRemoteConnectorServer", msg);
                     throw new AgentConfigurationError(
                             FILE_ACCESS_NOT_RESTRICTED, restrictedFileName);
                 }
@@ -672,6 +711,7 @@
     private static JMXConnectorServerData exportMBeanServer(
             MBeanServer mbs,
             int port,
+            int rmiPort,
             boolean useSsl,
             boolean useRegistrySsl,
             String sslConfigFileName,
@@ -689,7 +729,7 @@
          * IDs.  */
         System.setProperty("java.rmi.server.randomIDs", "true");
 
-        JMXServiceURL url = new JMXServiceURL("rmi", null, 0);
+        JMXServiceURL url = new JMXServiceURL("rmi", null, rmiPort);
 
         Map<String, Object> env = new HashMap<String, Object>();
 
@@ -746,7 +786,6 @@
             }
         }
 
-        final Registry registry;
         if (useRegistrySsl) {
             registry =
                     new SingleEntryRegistry(port, csf, ssf,
@@ -757,10 +796,12 @@
                     "jmxrmi", exporter.firstExported);
         }
 
-        JMXServiceURL remoteURL = new JMXServiceURL(
-                "service:jmx:rmi:///jndi/rmi://" + url.getHost() + ":" +
-                ((UnicastRef) ((RemoteObject) registry).getRef()).getLiveRef().getPort() +
-                "/jmxrmi");
+
+        int registryPort =
+            ((UnicastRef) ((RemoteObject) registry).getRef()).getLiveRef().getPort();
+        String jmxUrlStr =  String.format("service:jmx:rmi:///jndi/rmi://%s:%d/jmxrmi",
+                                           url.getHost(), registryPort);
+        JMXServiceURL remoteURL = new JMXServiceURL(jmxUrlStr);
 
         /* Our exporter remembers the first object it was asked to
         export, which will be an RMIServerImpl appropriate for
--- a/src/share/classes/sun/management/resources/agent.properties	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/classes/sun/management/resources/agent.properties	Wed Mar 07 17:23:03 2012 -0800
@@ -1,6 +1,6 @@
 #
 #
-# Copyright (c) 2004, 2005, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
@@ -43,8 +43,9 @@
 agent.err.premain.notfound         = premain(String) does not exist in agent class
 agent.err.agentclass.access.denied = Access to premain(String) is denied
 agent.err.invalid.agentclass       = Invalid com.sun.management.agent.class property value
-
+agent.err.invalid.state            = Invalid agent state
 agent.err.invalid.jmxremote.port   = Invalid com.sun.management.jmxremote.port number
+agent.err.invalid.jmxremote.rmi.port = Invalid com.sun.management.jmxremote.rmi.port number
 
 agent.err.file.not.set               = File not specified
 agent.err.file.not.readable          = File not readable
@@ -78,11 +79,11 @@
 agent.err.snmp.adaptor.start.failed = Failed to start SNMP adaptor with address
 agent.err.snmp.mib.init.failed     = Failed to initialize SNMP MIB with error
 
-jmxremote.ConnectorBootstrap.initialize = Starting JMX Connector Server:
-jmxremote.ConnectorBootstrap.initialize.noAuthentication = No Authentication
-jmxremote.ConnectorBootstrap.initialize.ready = JMX Connector ready at: {0}
-jmxremote.ConnectorBootstrap.initialize.password.readonly = Password file read access must be restricted: {0}
-jmxremote.ConnectorBootstrap.initialize.file.readonly = File read access must be restricted: {0}
+jmxremote.ConnectorBootstrap.starting = Starting JMX Connector Server:
+jmxremote.ConnectorBootstrap.noAuthentication = No Authentication
+jmxremote.ConnectorBootstrap.ready = JMX Connector ready at: {0}
+jmxremote.ConnectorBootstrap.password.readonly = Password file read access must be restricted: {0}
+jmxremote.ConnectorBootstrap.file.readonly = File read access must be restricted: {0}
 
 jmxremote.AdaptorBootstrap.getTargetList.processing = Processing ACL
 jmxremote.AdaptorBootstrap.getTargetList.adding = Adding target: {0}
--- a/src/share/lib/security/java.security-macosx	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/lib/security/java.security-macosx	Wed Mar 07 17:23:03 2012 -0800
@@ -124,7 +124,7 @@
 # passed to checkPackageAccess unless the
 # corresponding RuntimePermission ("accessClassInPackage."+package) has
 # been granted.
-package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,apple.
+package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,apple.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # List of comma-separated packages that start with or equal this string
--- a/src/share/lib/security/java.security-solaris	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/lib/security/java.security-solaris	Wed Mar 07 17:23:03 2012 -0800
@@ -125,7 +125,7 @@
 # passed to checkPackageAccess unless the
 # corresponding RuntimePermission ("accessClassInPackage."+package) has
 # been granted.
-package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.
+package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # List of comma-separated packages that start with or equal this string
--- a/src/share/lib/security/java.security-windows	Thu Mar 01 13:45:02 2012 -0800
+++ b/src/share/lib/security/java.security-windows	Wed Mar 07 17:23:03 2012 -0800
@@ -124,7 +124,7 @@
 # passed to checkPackageAccess unless the
 # corresponding RuntimePermission ("accessClassInPackage."+package) has
 # been granted.
-package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.
+package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.
 
 #
 # List of comma-separated packages that start with or equal this string
--- a/test/ProblemList.txt	Thu Mar 01 13:45:02 2012 -0800
+++ b/test/ProblemList.txt	Wed Mar 07 17:23:03 2012 -0800
@@ -287,6 +287,9 @@
 # Windows X64, java.lang.IllegalStateException
 javax/management/monitor/AttributeArbitraryDataTypeTest.java    generic-all
 
+# 7149181 
+sun/management/jmxremote/startstop/JMXStartStopTest.sh          generic-all
+
 ############################################################################
 
 # jdk_math
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/java/lang/SecurityManager/CheckPackageAccess.java	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 7146431
+ * @summary Test that internal JAXP packages cannot be accessed
+ */
+
+public class CheckPackageAccess {
+
+    public static void main(String[] args) throws Exception {
+
+        String[] pkgs = new String[] {
+            "com.sun.org.apache.xerces.internal.utils.",
+            "com.sun.org.apache.xalan.internal.utils." };
+        SecurityManager sm = new SecurityManager();
+        System.setSecurityManager(sm);
+        for (String pkg : pkgs) {
+            System.out.println("Checking package access for " + pkg);
+            try {
+                sm.checkPackageAccess(pkg);
+                throw new Exception("Expected SecurityException not thrown");
+            } catch (SecurityException se) { }
+        }
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/javax/swing/JViewport/7107099/bug7107099.java	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,104 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/* @test
+   @bug 7107099
+   @summary JScrollBar does not show up even if there are enough lebgth of textstring in textField
+   @author Pavel Porvatov
+*/
+
+import sun.awt.SunToolkit;
+
+import javax.swing.*;
+import java.awt.*;
+
+public class bug7107099 {
+    private static JFrame frame;
+    private static JTextArea textarea;
+    private static JScrollPane scrollPane;
+
+    private static int value;
+    private static int min;
+    private static int max;
+    private static int extent;
+
+    public static void main(String[] args) throws Exception {
+        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                textarea = new JTextArea("before###1###\nbefore###2###\nbefore###3###\nbefore###4###\nbefore###5###\n");
+
+                scrollPane = new JScrollPane(textarea);
+                scrollPane.setPreferredSize(new Dimension(100, 50));
+
+                frame = new JFrame();
+                frame.setLayout(new BorderLayout());
+                frame.setSize(200, 200);
+                frame.add(scrollPane, BorderLayout.SOUTH);
+                frame.setVisible(true);
+            }
+        });
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
+
+                value = model.getValue();
+                min = model.getMinimum();
+                max = model.getMaximum();
+                extent = model.getExtent();
+
+                // Do tricky manipulation for testing purpose
+                textarea.setText(null);
+                scrollPane.setViewportView(textarea);
+                textarea.setText("after###1###\nafter###1###\nafter###1###\nafter###1###\nafter###1###\n");
+                textarea.setCaretPosition(0);
+            }
+        });
+
+        toolkit.realSync();
+
+        SwingUtilities.invokeAndWait(new Runnable() {
+            @Override
+            public void run() {
+                BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
+
+                if (value != model.getValue() ||
+                        min != model.getMinimum() ||
+                        max != model.getMaximum() ||
+                        extent != model.getExtent()) {
+                    throw new RuntimeException("Test bug7107099 failed");
+                }
+
+                System.out.println("Test bug7107099 passed");
+
+                frame.dispose();
+            }
+        });
+    }
+}
--- a/test/sun/management/AgentCheckTest.java	Thu Mar 01 13:45:02 2012 -0800
+++ b/test/sun/management/AgentCheckTest.java	Wed Mar 07 17:23:03 2012 -0800
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -35,10 +35,10 @@
     public static void main(String[] args){
         String [][] testStrings = {
             {"agent.err.error", "", ""},
-            {"jmxremote.ConnectorBootstrap.initialize", "", ""},
-            {"jmxremote.ConnectorBootstrap.initialize.noAuthentication", "", ""},
-            {"jmxremote.ConnectorBootstrap.initialize.ready", "Phony JMXServiceURL", ""},
-            {"jmxremote.ConnectorBootstrap.initialize.password.readonly", "Phony passwordFileName", ""},
+            {"jmxremote.ConnectorBootstrap.starting", "", ""},
+            {"jmxremote.ConnectorBootstrap.noAuthentication", "", ""},
+            {"jmxremote.ConnectorBootstrap.ready", "Phony JMXServiceURL", ""},
+            {"jmxremote.ConnectorBootstrap.password.readonly", "Phony passwordFileName", ""},
             {"jmxremote.AdaptorBootstrap.getTargetList.processing", "", ""},
             {"jmxremote.AdaptorBootstrap.getTargetList.adding", "Phony target", ""},
             {"jmxremote.AdaptorBootstrap.getTargetList.starting", "", ""},
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/management/jmxremote/startstop/JMXStartStopDoSomething.java	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.RandomAccessFile;
+
+public class JMXStartStopDoSomething {
+
+
+    public void doSomething(){
+        try {
+            for (int i=0; i < 10; ++i) {
+                RandomAccessFile f = new RandomAccessFile("/dev/null","r");
+                int n = f.read();
+                f.close();
+            }
+
+        } catch (Throwable e) {
+            System.err.println("Something bad happens:" +e);
+        }
+    }
+
+    public static void main(String args[]) throws Exception {
+        System.err.println("main enter");
+        int count = 1;
+        while(count > 0) {
+            JMXStartStopDoSomething p = new JMXStartStopDoSomething();
+            p.doSomething();
+            Thread.sleep(1);
+        }
+        // System.err.println("main exit");
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/management/jmxremote/startstop/JMXStartStopTest.java	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,181 @@
+/*
+ * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FilenameFilter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.rmi.registry.LocateRegistry;
+import java.rmi.registry.Registry;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.management.*;
+import javax.management.remote.*;
+
+import sun.management.AgentConfigurationError;
+import sun.management.jmxremote.ConnectorBootstrap;
+
+public class JMXStartStopTest {
+
+    static boolean verbose = false;
+
+    static void dbg_print(String msg){
+        if (verbose) {
+            System.err.println("DBG: " +msg);
+        }
+    }
+
+    static void dbg_print(String msg, Throwable ex){
+        if (verbose) {
+            System.err.println("DBG: " + msg + " " + ex.getMessage() );
+            ex.printStackTrace(System.err);
+        }
+    }
+
+    public static int listMBeans(MBeanServerConnection server, ObjectName pattern, QueryExp query)
+    throws Exception {
+
+        Set names = server.queryNames(pattern,query);
+        for (Iterator i=names.iterator(); i.hasNext(); ) {
+            ObjectName name = (ObjectName)i.next();
+            MBeanInfo info = server.getMBeanInfo(name);
+            dbg_print("Got MBean: " + name);
+
+            MBeanAttributeInfo[] attrs = info.getAttributes();
+            if (attrs == null)
+                continue;
+
+            for (int j=0; j<attrs.length; j++) {
+                if (attrs[j].isReadable()) {
+                    Object o = server.getAttribute(name,attrs[j].getName());
+                }
+            }
+        }
+        return names.size();
+    }
+
+
+    public void run_local(String strPid)
+    throws Exception {
+
+        String jmxUrlStr = null;
+        int pid = Integer.parseInt(strPid);
+
+        try {
+            jmxUrlStr = sun.management.ConnectorAddressLink.importFrom(pid);
+            dbg_print("Local Service URL: " +jmxUrlStr);
+            if ( jmxUrlStr == null ) {
+                throw new Exception("No Service URL. Local agent not started?");
+            }
+
+            JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
+            Map m = new HashMap();
+
+            JMXConnector c = JMXConnectorFactory.connect(url,m);
+
+            MBeanServerConnection conn = c.getMBeanServerConnection();
+            ObjectName pattern = new ObjectName("java.lang:type=Memory,*");
+
+            int count = listMBeans(conn,pattern,null);
+            if (count == 0)
+                throw new Exception("Expected at least one matching "+ "MBean for "+pattern);
+
+
+        } catch (IOException e) {
+            dbg_print("Cannot find process : " + pid);
+            throw e;
+        }
+    }
+
+    public void run(String args[]) throws Exception {
+
+        dbg_print("RmiRegistry lookup...");
+
+        int port = 4567;
+        if (args != null && args.length > 0) {
+            port = Integer.parseInt(args[0]);
+        }
+        dbg_print("Using port: " + port);
+
+        int rmiPort = 0;
+        if (args != null && args.length > 1) {
+            rmiPort = Integer.parseInt(args[1]);
+        }
+        dbg_print("Using rmi port: " + rmiPort);
+
+        Registry registry = LocateRegistry.getRegistry(port);
+
+        // "jmxrmi"
+        String[] relist = registry.list();
+        for (int i = 0; i < relist.length; ++i) {
+            dbg_print("Got registry: " + relist[i]);
+        }
+
+        String jmxUrlStr = (rmiPort != 0) ?
+                           String.format("service:jmx:rmi://localhost:%d/jndi/rmi://localhost:%d/jmxrmi", rmiPort, port) :
+                           String.format("service:jmx:rmi:///jndi/rmi://localhost:%d/jmxrmi",port);
+
+        JMXServiceURL url = new JMXServiceURL(jmxUrlStr);
+        Map m = new HashMap();
+
+        JMXConnector c = JMXConnectorFactory.connect(url,m);
+
+        MBeanServerConnection conn = c.getMBeanServerConnection();
+        ObjectName pattern = new ObjectName("java.lang:type=Memory,*");
+
+        int count = listMBeans(conn,pattern,null);
+        if (count == 0)
+            throw new Exception("Expected at least one matching "+ "MBean for "+pattern);
+    }
+
+
+    public static void main(String args[]) {
+        JMXStartStopTest manager = new JMXStartStopTest();
+        try {
+            if (args!=null && args[0].equals("local")) {
+                manager.run_local(args[1]);
+            } else {
+                manager.run(args);
+            }
+        } catch (RuntimeException r) {
+            dbg_print("No connection: ", r);
+            System.out.println("NO_CONN");
+            System.exit(1);
+        } catch (Throwable t) {
+            dbg_print("No connection: ", t);
+            System.out.println("NO_CONN");
+            System.exit(2);
+        }
+        System.out.println("OK_CONN");
+        System.exit(0);
+    }
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/management/jmxremote/startstop/JMXStartStopTest.sh	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,603 @@
+#!/bin/sh
+
+# Copyright (c) 2011, 2012 Oracle and/or its affiliates. All rights reserved.
+# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+# 
+# This code is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License version 2 only, as
+# published by the Free Software Foundation.
+# 
+# This code is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# version 2 for more details (a copy is included in the LICENSE file that
+# accompanied this code).
+# 
+# You should have received a copy of the GNU General Public License version
+# 2 along with this work; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+#
+# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+# or visit www.oracle.com if you need additional information or have any
+# questions.
+
+# @test
+# @bug 7110104
+# @build JMXStartStopTest JMXStartStopDoSomething
+# @run shell JMXStartStopTest.sh --jtreg --no-compile
+# @summary No word Failed expected in the test output
+
+_verbose=no
+_server=no
+_jtreg=no
+_compile=yes
+_testsuite="01,02,03,04,05,06,07,08,09,10,11,12,13"
+_port_one=50234
+_port_two=50235
+
+
+_testclasses=".classes"
+_testsrc=`pwd`
+
+_logname=".classes/JMXStartStopTest_output.txt"
+
+
+_compile(){
+
+    if [ ! -e ${_testclasses} ]
+    then
+	  mkdir -p ${_testclasses} 
+    fi   
+
+    rm -f ${_testclasses}/JMXStartStopTest.class
+
+    # Compile testcase
+    ${TESTJAVA}/bin/javac -d ${_testclasses} JMXStartStopDoSomething.java JMXStartStopTest.java 
+
+    if [ ! -e ${_testclasses}/JMXStartStopTest.class ]
+    then
+      echo "ERROR: Can't compile"
+      exit -1
+    fi
+}
+
+_app_start(){
+
+  if [ "${_verbose}" = "yes" ]
+  then
+     echo "RUN: ${TESTJAVA}/bin/java -server $* -cp ${_testclasses} JMXStartStopDoSomething "
+  fi 
+  ${TESTJAVA}/bin/java -server $* -cp ${_testclasses} JMXStartStopDoSomething  >> ${_logname} 2>&1 &
+  sleep 1 
+
+  pid=`_get_pid`
+  if [ "x${pid}" = "x" ]
+  then
+     echo "ERROR: Test app not started"
+     exit -1
+  fi
+
+}
+
+_get_pid(){
+    ${TESTJAVA}/bin/jps | sed -n "/JMXStartStopDoSomething/s/ .*//p"
+}
+
+_app_stop(){
+    pid=`_get_pid`
+    if [ "x${pid}" != "x" ]
+    then
+       kill $pid
+    fi
+
+    # Stop on first failed test under jtreg
+    if [ "x$1" = "xFailed" -a "${_jtreg}" = "yes" ]
+    then
+      exit -1
+    fi
+}
+   
+testme(){
+    ${TESTJAVA}/bin/java -cp ${_testclasses} JMXStartStopTest $*
+}   
+
+  
+_jcmd(){
+  if [ "${_verbose}" = "yes" ]
+  then
+     echo "RUN: ${TESTJAVA}/bin/jcmd JMXStartStopDoSomething $*"
+     ${TESTJAVA}/bin/jcmd JMXStartStopDoSomething $* 
+  else
+     ${TESTJAVA}/bin/jcmd JMXStartStopDoSomething $* > /dev/null 2>/dev/null
+  fi
+} 
+
+_echo(){
+    echo "$*"
+    echo "$*" >> ${_logname}
+}
+   
+# ============= TESTS ======================================
+   
+test_01(){
+# Run an app with JMX enabled stop it and 
+# restart on other port
+		
+    _echo "**** Test one ****"		
+
+    _app_start  -Dcom.sun.management.jmxremote.port=$1 \
+                -Dcom.sun.management.jmxremote.authenticate=false \
+	        -Dcom.sun.management.jmxremote.ssl=false 
+
+    res1=`testme $1`
+
+    _jcmd ManagementAgent.stop
+
+    res2=`testme $1`
+
+    _jcmd ManagementAgent.start jmxremote.port=$2
+
+    res3=`testme $2`
+
+
+    if [ "${res1}" = "OK_CONN" -a "${res2}" = "NO_CONN" -a "${res3}" = "OK_CONN" ] 
+    then
+	_echo "Passed"
+    else
+	_echo "Failed r1(OK):${res1} r2(NO):${res2} r3(OK):${res3}"
+    _app_stop "Failed"
+    fi
+
+    _app_stop
+
+}  
+   
+test_02(){
+# Run an app without JMX enabled 
+# start JMX by jcmd
+
+_echo "**** Test two ****"		
+_app_start  
+
+_jcmd ManagementAgent.start jmxremote.port=$1 jmxremote.authenticate=false jmxremote.ssl=false 
+
+res1=`testme $1`
+
+if [ "${res1}" = "OK_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(OK):${res1}"
+    _app_stop "Failed"
+fi
+
+_app_stop
+
+}   
+   
+test_03(){
+# Run an app without JMX enabled 
+# start JMX by jcmd on one port than on other one
+
+_echo "**** Test three ****"		
+_app_start  
+
+_jcmd ManagementAgent.start jmxremote.port=$1 jmxremote.authenticate=false jmxremote.ssl=false 
+
+# Second agent shouldn't start
+_jcmd ManagementAgent.start jmxremote.port=$2 jmxremote.authenticate=false jmxremote.ssl=false
+
+# First agent should connect
+res1=`testme $1`
+
+if [ "${res1}" = "OK_CONN" ] 
+then
+    _echo "Passed $1"
+else
+    _echo "Failed r1(NO):${res1}"
+    _app_stop "Failed"
+fi
+
+#Second agent shouldn't connect
+res1=`testme $2`
+
+if [ "${res1}" = "NO_CONN" ] 
+then
+    _echo "Passed $2"
+else
+    _echo "Failed r1(OK):${res1}"
+fi
+
+_app_stop
+}   
+   
+test_04(){
+# Run an app without JMX enabled 
+# start JMX by jcmd on one port, specify rmi port explicitly
+
+_echo "**** Test four ****"		
+_app_start  
+
+_jcmd ManagementAgent.start jmxremote.port=$1 jmxremote.rmi.port=$2 jmxremote.authenticate=false jmxremote.ssl=false 
+
+# First agent should connect
+res1=`testme $1 $2`
+
+if [ "${res1}" = "OK_CONN" ] 
+then
+    _echo "Passed $1 $2"
+else
+    _echo "Failed r1(NO):${res1}"
+    _app_stop "Failed"
+fi
+
+_app_stop
+}   
+
+test_05(){
+# Run an app without JMX enabled, it will enable local server
+# but should leave remote server disabled  
+
+_echo "**** Test five ****"		
+_app_start  
+
+_jcmd ManagementAgent.start jmxremote=1 
+
+# First agent should connect
+res1=`testme $1`
+
+if [ "${res1}" = "NO_CONN" ] 
+then
+    _echo "Passed $1 $2"
+else
+    _echo "Failed r1(OK):${res1}"
+    _app_stop "Failed"
+fi
+
+_app_stop
+}   
+
+test_06(){
+# Run an app without JMX enabled 
+# start JMX by jcmd on one port, specify rmi port explicitly
+# attempt to start it again
+# 1) with the same port 
+# 2) with other port
+# 3) attempt to stop it twice
+# Check for valid messages in the output	
+
+_echo "**** Test six ****"		
+_app_start  
+
+_jcmd ManagementAgent.start jmxremote.port=$1 jmxremote.authenticate=false jmxremote.ssl=false 
+
+# First agent should connect
+res1=`testme $1 $2`
+
+if [ "${res1}" = "OK_CONN" ] 
+then
+    _echo "Passed $1 $2"
+else
+    _echo "Failed r1(NO):${res1}"
+    _app_stop "Failed"
+fi
+
+_jcmd ManagementAgent.start jmxremote.port=$1 jmxremote.authenticate=false jmxremote.ssl=false 
+
+_jcmd ManagementAgent.start jmxremote.port=$2 jmxremote.authenticate=false jmxremote.ssl=false 
+
+_jcmd ManagementAgent.stop
+
+_jcmd ManagementAgent.stop
+
+_jcmd ManagementAgent.start jmxremote.port=22 jmxremote.rmi.port=$2 jmxremote.authenticate=false jmxremote.ssl=false 
+
+_app_stop
+}   
+
+test_07(){
+# Run an app without JMX enabled, but with some properties set 
+# in command line.
+# make sure these properties overriden corectly 
+
+_echo "**** Test seven ****"		
+
+_app_start   -Dcom.sun.management.jmxremote.authenticate=false \
+             -Dcom.sun.management.jmxremote.ssl=true 
+
+res1=`testme $1`
+
+_jcmd ManagementAgent.start jmxremote.port=$2 jmxremote.authenticate=false jmxremote.ssl=false
+
+res2=`testme $2`
+
+
+if [ "${res1}" = "NO_CONN" -a "${res2}" = "OK_CONN" ] 
+then
+   echo "Passed"
+else
+	_echo "Failed r1(NO):${res1} r2(OK):${res2}"
+    _app_stop "Failed"
+fi
+
+_app_stop
+}   
+
+test_08(){
+# Run an app with JMX enabled and with some properties set 
+# in command line.
+# stop JMX agent and then start it again with different property values
+# make sure these properties overriden corectly 
+
+_echo "**** Test eight ****"		
+
+_app_start  -Dcom.sun.management.jmxremote.port=$1 \
+	    -Dcom.sun.management.jmxremote.authenticate=false \
+	    -Dcom.sun.management.jmxremote.ssl=true 
+
+res1=`testme $1`
+
+_jcmd ManagementAgent.stop
+
+res2=`testme $1`
+
+_jcmd ManagementAgent.start jmxremote.port=$2 jmxremote.authenticate=false jmxremote.ssl=false
+
+res3=`testme $2`
+
+
+if [ "${res1}" = "NO_CONN" -a "${res2}" = "NO_CONN" -a "${res3}" = "OK_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(NO):${res1} r2(NO):${res2} r3(OK):${res3}"
+    _app_stop "Failed"
+fi
+ 
+_app_stop
+}   
+
+test_09(){
+# Run an app with JMX enabled and with some properties set 
+# in command line.
+# stop JMX agent and then start it again with different property values
+# specifing some property in management config file and some of them
+# in command line
+# make sure these properties overriden corectly 
+
+_echo "**** Test nine ****"		
+
+_app_start -Dcom.sun.management.config.file=${_testsrc}/management_cl.properties \
+           -Dcom.sun.management.jmxremote.authenticate=false 
+
+res1=`testme $1`
+
+_jcmd ManagementAgent.stop
+
+res2=`testme $1`
+
+_jcmd ManagementAgent.start config.file=${_testsrc}/management_jcmd.properties \
+       jmxremote.authenticate=false jmxremote.port=$2
+
+res3=`testme $2`
+
+if [ "${res1}" = "NO_CONN" -a "${res2}" = "NO_CONN" -a "${res3}" = "OK_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(NO):${res1} r2(NO):${res2} r3(OK):${res3}"
+    _app_stop "Failed"
+fi
+ 
+_app_stop
+}   
+
+test_10(){
+# Run an app with JMX enabled and with some properties set 
+# in command line.
+# stop JMX agent and then start it again with different property values
+# stop JMX agent again and then start it without property value
+# make sure these properties overriden corectly 
+
+_echo "**** Test ten ****"		
+
+_app_start  -Dcom.sun.management.jmxremote.port=$1 \
+	    -Dcom.sun.management.jmxremote.authenticate=false \
+	    -Dcom.sun.management.jmxremote.ssl=true 
+
+res1=`testme $1`
+
+_jcmd ManagementAgent.stop
+_jcmd ManagementAgent.start jmxremote.ssl=false jmxremote.port=$1
+
+
+res2=`testme $1`
+
+_jcmd ManagementAgent.stop
+_jcmd ManagementAgent.start jmxremote.port=$1
+
+res3=`testme $1`
+
+if [ "${res1}" = "NO_CONN" -a "${res2}" = "OK_CONN" -a "${res3}" = "NO_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(NO):${res1} r2(OK):${res2} r3(NO):${res3}"
+    _app_stop "Failed"
+fi
+ 
+_app_stop
+}   
+
+test_11(){
+# Run an app with JMX enabled 
+# stop remote agent 
+# make sure local agent is not affected
+
+_echo "**** Test eleven ****"		
+
+_app_start  -Dcom.sun.management.jmxremote.port=$2 \
+	    -Dcom.sun.management.jmxremote.authenticate=false \
+	    -Dcom.sun.management.jmxremote.ssl=false 
+	  
+res1=`testme $2`
+
+_jcmd ManagementAgent.stop
+
+pid=`${TESTJAVA}/bin/jps | sed -n "/JMXStartStopDoSomething/s/ .*//p"`
+res2=`testme local ${pid}`
+
+if [ "${res1}" = "OK_CONN" -a "${res2}" = "OK_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(OK):${res1} r2(OK):${res2}"
+    _app_stop "Failed"
+fi
+ 
+_app_stop
+}   
+
+test_12(){
+# Run an app with JMX disabled 
+# start local agent only
+
+_echo "**** Test twelve ****"		
+
+_app_start 
+	  
+res1=`testme $1`
+
+_jcmd ManagementAgent.start_local
+
+pid=`_get_pid`
+if [ "x${pid}" = "x" ]
+then
+  res2="NO_CONN"
+else
+  res2=`testme local ${pid}`
+fi
+
+if [ "${res1}" = "NO_CONN" -a "${res2}" = "OK_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(NO):${res1} r2(OK):${res2}"
+    _app_stop "Failed"
+fi
+ 
+_app_stop
+}   
+
+test_13(){
+# Run an app with -javaagent make sure it works as expected - system properties are ignored
+
+_echo "**** Test 13 ****"		
+
+AGENT="${TESTJAVA}/jre/lib/management-agent.jar"
+if [ ! -f ${AGENT} ]
+ then
+  AGENT="${TESTJAVA}/lib/management-agent.jar"
+fi
+
+_app_start -javaagent:${AGENT}=com.sun.management.jmxremote.port=$1,com.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false 
+	  
+res1=`testme $1`
+
+if [ "${res1}" = "NO_CONN" ] 
+then
+    _echo "Passed"
+else
+    _echo "Failed r1(NO):${res1}"
+    _app_stop "Failed"
+fi
+ 
+_app_stop
+}   
+
+
+#============== Server tests =======================
+
+server_test_01(){
+		
+    _echo "**** Server test one ****"		
+
+    _app_start  -Dcom.sun.management.jmxremote.port=$1 \
+                -Dcom.sun.management.jmxremote.rmi.port=$2 \
+                -Dcom.sun.management.jmxremote.authenticate=false \
+                -Dcom.sun.management.jmxremote.ssl=false 
+
+}  
+
+ 
+# ============= MAIN =======================================
+
+if [ "x${TESTJAVA}" = "x" ]
+then
+  echo "TESTJAVA env have to be set"
+  exit
+fi
+
+if [ ! -x "${TESTJAVA}/bin/jcmd" ]
+then
+  echo "${TESTJAVA}/bin/jcmd"
+  echo "Doesn't exist or not an executable"
+
+  if [ "${_verbose}" != "yes" ]
+  then
+    exit
+  fi
+fi
+
+
+#------------------------------------------------------------------------------
+# reading parameters 
+
+for parm in "$@"  
+do
+   case $parm in
+  --verbose)      _verbose=yes  ;;
+  --server)       _server=yes   ;;
+  --jtreg)        _jtreg=yes    ;;
+  --no-compile)   _compile=no   ;;
+  --testsuite=*)  _testsuite=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
+  --port-one=*)   _port_one=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
+  --port-two=*)   _port_two=`_echo $parm | sed "s,^--.*=\(.*\),\1,"`  ;;
+  *) 
+     echo "Undefined parameter $parm. Try --help for help" 
+     exit 
+   ;;
+ esac 
+done
+
+if [ ${_compile} = "yes" ]
+then
+ _compile
+fi
+
+if [ ${_jtreg} = "yes" ]
+then
+ _testclasses=${TESTCLASSES}
+ _testsrc=${TESTSRC}
+ _logname="JMXStartStopTest_output.txt"
+fi
+
+rm -f ${_logname}
+
+# Start server mode tests
+# All of them require manual cleanup
+if [ "x${_server}" = "xyes" ]
+then
+  
+ server_test_01 ${_port_one} ${_port_two}
+
+else
+
+ # Local mode tests
+ for i in `echo ${_testsuite} | sed -e "s/,/ /g"`
+ do
+  test_${i} ${_port_one} ${_port_two}
+ done
+
+fi
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/management/jmxremote/startstop/REMOTE_TESTING.txt	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,11 @@
+1. Setup two hosts
+2. Make sure tcp connection between them works
+3. run tcpdump -i <interface> host <host2_name> and 'tcp[13] & 2!=0'
+   on host 1
+4. run JMXStartStopTest.sh --server on host2
+5. run jconsole on host1
+6. connect jconsole to host2:50234
+   Make sure jconsole works
+   Make sure only host2.50234 and host2.50235 appears in tcpdump output.
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/management/jmxremote/startstop/management_cl.properties	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,2 @@
+com.sun.management.jmxremote.ssl=true
+com.sun.management.internal.read_from_config_file_cl=true
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/sun/management/jmxremote/startstop/management_jcmd.properties	Wed Mar 07 17:23:03 2012 -0800
@@ -0,0 +1,3 @@
+com.sun.management.jmxremote.ssl=false
+jmxremote.authenticate=true
+com.sun.management.internal.read_from_config_file_jcmd=true