--- old/make/data/jdwp/jdwp.spec Thu Dec 10 01:42:33 2015 +++ new/make/data/jdwp/jdwp.spec Thu Dec 10 01:42:32 2015 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -569,6 +569,21 @@ (Error VM_DEAD) ) ) + (Command AllModules=22 + "Returns all modules in the target VM." + "
Since JDWP version 1.9." + (Out + ) + (Reply + (Repeat modules "The number of the modules that follow." + (moduleID module "One of the modules.") + ) + ) + (ErrorSet + (Error NOT_IMPLEMENTED) + (Error VM_DEAD) + ) + ) ) (CommandSet ReferenceType=2 @@ -1029,6 +1044,22 @@ (Error VM_DEAD) ) ) + (Command Module=19 + "Returns the module this reference type belongs to." + "
Since JDWP version 1.9." + (Out + (referenceType refType "The reference type.") + ) + (Reply + (moduleID module "The module this reference type belongs to.") + ) + (ErrorSet + (Error INVALID_CLASS "refType is not the ID of a reference type.") + (Error INVALID_OBJECT "refType is not a known ID.") + (Error NOT_IMPLEMENTED) + (Error VM_DEAD) + ) + ) ) (CommandSet ClassType=3 (Command Superclass=1 @@ -2647,6 +2678,54 @@ ) ) ) +(CommandSet Module=18 + (Command Name=1 + "Returns the name of this module." + "
Since JDWP version 1.9." + (Out + (moduleID module "This module.") + ) + (Reply + (string name "The module's name.") + ) + (ErrorSet + (Error INVALID_MODULE) + (Error NOT_IMPLEMENTED) + (Error VM_DEAD) + ) + ) + (Command ClassLoader=2 + "Returns the class loader of this module." + "
Since JDWP version 1.9." + (Out + (moduleID module "This module.") + ) + (Reply + (classLoaderObject classLoader "The module's class loader.") + ) + (ErrorSet + (Error INVALID_MODULE) + (Error NOT_IMPLEMENTED) + (Error VM_DEAD) + ) + ) + (Command CanRead=3 + "Returns true if this module can read the target module; false otherwise." + "
Since JDWP version 1.9." + (Out + (moduleID module "This module.") + (moduleID tagetModule "The target module.") + ) + (Reply + (boolean canRead "true if this module can read the target module; false otherwise.") + ) + (ErrorSet + (Error INVALID_MODULE "This module or targetModule is not the ID of a module.") + (Error NOT_IMPLEMENTED) + (Error VM_DEAD) + ) + ) +) (CommandSet Event=64 (Command Composite=100 "Several events may occur at a given time in the target VM. " @@ -3054,6 +3133,7 @@ (Constant INVALID_SLOT =35 "Invalid slot.") (Constant DUPLICATE =40 "Item already set.") (Constant NOT_FOUND =41 "Desired element not found.") + (Constant INVALID_MODULE =42 "Invalid module.") (Constant INVALID_MONITOR =50 "Invalid monitor.") (Constant NOT_MONITOR_OWNER =51 "This thread doesn't own the monitor.") (Constant INTERRUPT =52 "The call has been interrupted before completion.") --- old/make/src/classes/build/tools/jdwpgen/Parse.java Thu Dec 10 01:42:33 2015 +++ new/make/src/classes/build/tools/jdwpgen/Parse.java Thu Dec 10 01:42:33 2015 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -80,6 +80,7 @@ kindMap.put("field", new FieldTypeNode()); kindMap.put("frame", new FrameTypeNode()); kindMap.put("string", new StringTypeNode()); + kindMap.put("moduleID", new ModuleTypeNode()); kindMap.put("value", new ValueTypeNode()); kindMap.put("byte", new ByteTypeNode()); kindMap.put("location", new LocationTypeNode()); --- old/src/java.base/share/native/include/jni.h Thu Dec 10 01:42:34 2015 +++ new/src/java.base/share/native/include/jni.h Thu Dec 10 01:42:34 2015 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1997, 2015, 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 @@ -770,7 +770,8 @@ jobject (JNICALL *GetModule) (JNIEnv* env, jclass clazz); - + jsize (JNICALL *GetAllModules) + (JNIEnv* env, jobjectArray *modules); }; /* @@ -1868,8 +1869,10 @@ jobject GetModule(jclass clazz) { return functions->GetModule(this, clazz); } + jsize GetAllModules(jobjectArray *modules) { + return functions->GetAllModules(this, modules); + } - #endif /* __cplusplus */ }; --- old/src/jdk.jdi/share/classes/com/sun/jdi/ReferenceType.java Thu Dec 10 01:42:35 2015 +++ new/src/jdk.jdi/share/classes/com/sun/jdi/ReferenceType.java Thu Dec 10 01:42:34 2015 @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2013, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2015, 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 @@ -118,6 +118,21 @@ ClassLoaderReference classLoader(); /** + * Gets the module object which contains the class corresponding + * to this type. + * + * @return a {@link Module} which mirrors the module in the target VM. + * + * @throws java.lang.UnsupportedOperationException if + * the target virtual machine does not support this + * operation. + *
+ * + * @return a list of {@link Module} objects, each mirroring + * a module in the target VM. + * + * @throws java.lang.UnsupportedOperationException if + * the target virtual machine does not support this + * operation. + *
+ * + * @since 1.9 + */ +@jdk.Exported +public class InvalidModuleException extends RuntimeException { + private static final long serialVersionUID = 7907359387320658039L; + + public InvalidModuleException() { + super(); + } + + public InvalidModuleException(String s) { + super(s); + } +} --- /dev/null Thu Dec 10 01:42:47 2015 +++ new/src/jdk.jdi/share/classes/com/sun/jdi/Module.java Thu Dec 10 01:42:47 2015 @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2015, 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. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * 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. + */ + +package com.sun.jdi; + + +/** + * A module that currently exists in the target VM. + *
+ * Any method on Module
which directly or
+ * indirectly takes Module
as an parameter may throw
+ * {@link com.sun.jdi.VMDisconnectedException} if the target VM is
+ * disconnected and the {@link com.sun.jdi.event.VMDisconnectEvent} has been or is
+ * available to be read from the {@link com.sun.jdi.event.EventQueue}.
+ *
+ * Any method on Module
which directly or
+ * indirectly takes Module
as an parameter may throw
+ * {@link com.sun.jdi.VMOutOfMemoryException} if the target VM has run out of memory.
+ *
+ * Any method on Module
or which directly or indirectly takes
+ * Module
as parameter may throw
+ * {@link com.sun.jdi.InvalidModuleException} if the mirrored module
+ * has been unloaded.
+ *
+ * @since 1.9
+ */
+@jdk.Exported
+public interface Module extends Mirror {
+
+ /**
+ * Returns the module name.
+ * This method returns {@code null}
+ * if this module is an unnamed module.
+ *
+ * @return the name of this module.
+ * @throws java.lang.UnsupportedOperationException if
+ * the target virtual machine does not support this
+ * operation.
+ */
+ String name();
+
+ /**
+ * Returns the {@link ClassLoaderReference} object for this module.
+ *
+ * @return the {@link ClassLoaderReference} object for this module.
+ * @throws java.lang.UnsupportedOperationException if
+ * the target virtual machine does not support this
+ * operation.
+ */
+ ClassLoaderReference classLoader();
+
+ /**
+ * Determines if this module has a read edge
+ * with the target {@link Module} module.
+ *
+ * @return true
if the target {@link Module}
+ * module is readable, false
otherwise.
+ * @throws java.lang.UnsupportedOperationException if
+ * the target virtual machine does not support this
+ * operation.
+ */
+ boolean canRead(Module module);
+}
--- /dev/null Thu Dec 10 01:42:48 2015
+++ new/src/jdk.jdi/share/classes/com/sun/tools/jdi/ModuleImpl.java Thu Dec 10 01:42:48 2015
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2015, 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. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package com.sun.tools.jdi;
+
+import com.sun.jdi.*;
+import com.sun.jdi.Module;
+
+
+class ModuleImpl extends MirrorImpl implements Module {
+ private long ref = 0L;
+
+ protected ModuleImpl(VirtualMachine aVm, long aRef) {
+ super(aVm);
+ ref = aRef;
+ }
+
+ protected long ref() {
+ return ref;
+ }
+
+ protected String description() {
+ return "Module " + ref();
+ }
+
+ private String name;
+ private ClassLoaderReference classLoader;
+
+ private boolean cachedName = false;
+ private boolean cachedClassLoader = false;
+
+
+ public synchronized String name() {
+ if (cachedName) {
+ return name;
+ }
+ try {
+ name = JDWP.Module.Name.process(this.vm, this).name;
+ if (name != null && name.length() == 0) {
+ // The JDWP returns empty name for unnamed modules
+ name = null;
+ }
+ cachedName = true;
+ } catch (JDWPException ex) {
+ throw ex.toJDIException();
+ }
+ return name;
+ }
+
+ public synchronized ClassLoaderReference classLoader() {
+ if (cachedClassLoader) {
+ return classLoader;
+ }
+ try {
+ classLoader = JDWP.Module.ClassLoader.process(this.vm, this).classLoader;
+ cachedClassLoader = true;
+ } catch (JDWPException ex) {
+ throw ex.toJDIException();
+ }
+ return classLoader;
+ }
+
+ public synchronized boolean canRead(Module module) {
+ boolean ret;
+ try {
+ ret = JDWP.Module.CanRead.process(this.vm, this, (ModuleImpl)module).canRead;
+ } catch (JDWPException ex) {
+ throw ex.toJDIException();
+ }
+ return ret;
+ }
+}
--- /dev/null Thu Dec 10 01:42:48 2015
+++ new/src/jdk.jdwp.agent/share/native/libjdwp/ModuleImpl.c Thu Dec 10 01:42:48 2015
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2015, 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. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+#include "util.h"
+#include "inStream.h"
+#include "outStream.h"
+#include "ModuleImpl.h"
+
+
+static jclass jlrM(JNIEnv *env) {
+ return findClass(env, "Ljava/lang/reflect/Module;");
+}
+
+static jboolean
+getName(PacketInputStream *in, PacketOutputStream *out)
+{
+ static jmethodID method = NULL;
+ JNIEnv *env = getEnv();
+ char *name;
+ jstring namestr;
+ jobject module;
+
+ if (method == NULL) {
+ method = getMethod(env, jlrM(env), "getName", "()Ljava/lang/String;");
+ }
+ module = inStream_readModuleRef(getEnv(), in);
+ if (inStream_error(in)) {
+ return JNI_TRUE;
+ }
+ namestr = (jstring)JNI_FUNC_PTR(env, CallObjectMethod) (env, module, method);
+ if (namestr != NULL) {
+ name = (char*)JNI_FUNC_PTR(env, GetStringUTFChars)(env, namestr, NULL);
+ } else {
+ // The JDWP converts null into an empty string
+ }
+ (void)outStream_writeString(out, name);
+ jvmtiDeallocate(name);
+
+ return JNI_TRUE;
+}
+
+static jboolean
+getClassLoader(PacketInputStream *in, PacketOutputStream *out)
+{
+ static jmethodID method = NULL;
+ JNIEnv *env = getEnv();
+ jobject loader;
+ jobject module;
+
+ if (method == NULL) {
+ method = getMethod(env, jlrM(env), "getClassLoader", "()Ljava/lang/ClassLoader;");
+ }
+ module = inStream_readModuleRef(env, in);
+ if (inStream_error(in)) {
+ return JNI_TRUE;
+ }
+ loader = JNI_FUNC_PTR(env, CallObjectMethod) (env, module, method);
+
+ (void)outStream_writeObjectRef(env, out, loader);
+ return JNI_TRUE;
+}
+
+static jboolean
+canRead(PacketInputStream *in, PacketOutputStream *out)
+{
+ static jmethodID method = NULL;
+ JNIEnv *env = getEnv();
+ jboolean can_read;
+ jobject module;
+ jobject target_module;
+
+ if (method == NULL) {
+ method = getMethod(env, jlrM(env), "canRead", "(Ljava/lang/reflect/Module;)Z");
+ }
+ module = inStream_readModuleRef(env, in);
+ if (inStream_error(in)) {
+ return JNI_TRUE;
+ }
+ target_module = inStream_readModuleRef(env, in);
+ if (inStream_error(in)) {
+ return JNI_TRUE;
+ }
+ can_read = JNI_FUNC_PTR(env, CallBooleanMethod)
+ (env, module, method, target_module);
+
+ (void)outStream_writeBoolean(out, can_read);
+ return JNI_TRUE;
+}
+
+
+void *Module_Cmds[] = { (void *)3
+ ,(void *)getName
+ ,(void *)getClassLoader
+ ,(void *)canRead
+};
--- /dev/null Thu Dec 10 01:42:49 2015
+++ new/src/jdk.jdwp.agent/share/native/libjdwp/ModuleImpl.h Thu Dec 10 01:42:49 2015
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2015, 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. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+extern void *Module_Cmds[];
--- /dev/null Thu Dec 10 01:42:50 2015
+++ new/test/com/sun/jdi/ModulesTest.java Thu Dec 10 01:42:49 2015
@@ -0,0 +1,153 @@
+/*
+ * Copyright (c) 2015, 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 8049365
+ * @summary Tests the JDI and JDWP update for modules
+ *
+ * @modules jdk.jdi
+ * @run build TestScaffold VMConnection TargetListener TargetAdapter
+ * @run compile -g ModulesTest.java
+ * @run driver ModulesTest
+ */
+import com.sun.jdi.*;
+import com.sun.jdi.event.*;
+import com.sun.jdi.request.*;
+
+import java.util.*;
+
+ /********** target program **********/
+
+class ModulesTarg {
+ static int[] intArray = new int[10];
+
+ static {
+ // make sure our class loader "creates" int[] before tested
+ intArray[1] = 99;
+ }
+
+ public static void main(String[] args){
+ System.out.println("Goodbye from ModulesTarg!");
+ }
+}
+
+ /********** test program **********/
+
+public class ModulesTest extends TestScaffold {
+ ReferenceType targetClass;
+
+ ModulesTest (String args[]) {
+ super(args);
+ }
+
+ public static void main(String[] args) throws Exception {
+ new ModulesTest(args).startTests();
+ }
+
+ /********** test core **********/
+
+ private void checkClassLoader(Module module, ClassLoaderReference loader) {
+ List