changeset 5128:6ffe731d2b50

Improve +TracePackageAccess option Allow package access to be set on the unnamed package
author alanb
date Fri, 06 Sep 2013 14:26:25 +0100
parents f919f164ef4f
children 7444c00afcfe
files src/share/vm/classfile/classLoaderExports.cpp
diffstat 1 files changed, 14 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/classLoaderExports.cpp	Fri Aug 30 09:09:08 2013 -0700
+++ b/src/share/vm/classfile/classLoaderExports.cpp	Fri Sep 06 14:26:25 2013 +0100
@@ -105,7 +105,12 @@
   entry = new ClassLoaderExportEntry(hash, pkg);
   for (int i = 0; i < loaders->length(); i++) {
     hash = compute_hash(pkgs[i]);
-    entry->add_allow(tag_for(loaders->obj_at(i)), pkgs[i], hash);
+    int tag = tag_for(loaders->obj_at(i));
+    entry->add_allow(tag, pkgs[i], hash);
+    if (TracePackageAccess) {
+        tty->print_cr("setPackageAccess to allow access to %d:%s from %d:%s",
+            tag_for(loader), pkg, tag, pkgs[i]);
+    }
   }
 
   entry->set_next(first);
@@ -124,12 +129,10 @@
   ResourceMark rm;
   char* name = (char*) new_class->external_name();
   char* last = strrchr(name, '.');
-  if (last == NULL) {
-    // assume can't set access on the unnamed package for now
-    return true;
+  if (last != NULL) {
+    *last = '\0';
   }
-  *last = '\0';
-  const char* pkg = name;
+  const char* pkg = (last == NULL) ? "" : name;
 
   // package access setup for the package?
   ClassLoaderExportEntry* entry = exports->find_entry(pkg);
@@ -143,23 +146,18 @@
 
   name = (char*) current_class->external_name();
   last = strrchr(name, '.');
-  if (last == NULL) {
-    // assume can't set from unnamed package for now
-    if (TracePackageAccess) {
-        tty->print_cr("%s -> %s illegal access", current_class->external_name(),
-          new_class->external_name());
-    }
-    return false;
+  if (last != NULL) {
+    *last = '\0';
   }
-  *last = '\0';
-  pkg = name;
+  pkg = (last == NULL) ? "" : name;
 
   // check access list to see if access from current_class is allowed
   int tag = tag_for(current_class->class_loader());
   unsigned int hash = compute_hash(pkg);
   bool allowed = entry->can_access(tag, pkg, hash);
   if (TracePackageAccess) {
-    tty->print("%s -> %s", current_class->external_name(), new_class->external_name());
+    tty->print("%d:%s -> %d:%s", tag, current_class->external_name(),
+      tag_for(new_class->class_loader()), new_class->external_name());
     if (allowed) {
       tty->print_cr(" access allowed");
     } else {