--- /dev/null 2015-11-21 16:36:38.509275105 -0500 +++ new/test/runtime/logging/ProtectionDomainVerificationTest.java 2016-02-22 11:00:46.928570014 -0500 @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2016, 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 ProtectionDomainVerificationTest + * @bug 8149064 + * @library /testlibrary + * @compile Hello.java + * @build jdk.test.lib.OutputAnalyzer jdk.test.lib.Platform jdk.test.lib.ProcessTools + * @run driver ProtectionDomainVerificationTest + */ + +import jdk.test.lib.OutputAnalyzer; +import jdk.test.lib.Platform; +import jdk.test.lib.ProcessTools; + +public class ProtectionDomainVerificationTest { + + public static void main(String... args) throws Exception { + + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:protectiondomain=debug", + "-Xmx64m", + "Hello"); + OutputAnalyzer out = new OutputAnalyzer(pb.start()); + out.shouldContain("[protectiondomain] Checking package access"); + } +} --- old/src/share/vm/classfile/systemDictionary.cpp 2016-02-22 11:00:47.078389096 -0500 +++ new/src/share/vm/classfile/systemDictionary.cpp 2016-02-22 11:00:46.988669279 -0500 @@ -430,12 +430,14 @@ // Now we have to call back to java to check if the initating class has access JavaValue result(T_VOID); - if (TraceProtectionDomainVerification) { + if (log_is_enabled(Debug, protectiondomain)) { + ResourceMark rm; // Print out trace information - tty->print_cr("Checking package access"); - tty->print(" - class loader: "); class_loader()->print_value_on(tty); tty->cr(); - tty->print(" - protection domain: "); protection_domain()->print_value_on(tty); tty->cr(); - tty->print(" - loading: "); klass()->print_value_on(tty); tty->cr(); + outputStream* log = LogHandle(protectiondomain)::debug_stream(); + log->print_cr("Checking package access"); + log->print(" - class loader: "); class_loader()->print_value_on(log); log->cr(); + log->print(" - protection domain: "); protection_domain()->print_value_on(log); log->cr(); + log->print(" - loading: "); klass()->print_value_on(log); log->cr(); } KlassHandle system_loader(THREAD, SystemDictionary::ClassLoader_klass()); @@ -448,13 +450,15 @@ protection_domain, THREAD); - if (TraceProtectionDomainVerification) { + if (log_is_enabled(Debug, protectiondomain)) { + ResourceMark rm; + outputStream* log = LogHandle(protectiondomain)::debug_stream(); if (HAS_PENDING_EXCEPTION) { - tty->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!"); + log->print_cr(" -> DENIED !!!!!!!!!!!!!!!!!!!!!"); } else { - tty->print_cr(" -> granted"); + log->print_cr(" -> granted"); } - tty->cr(); + log->cr(); } if (HAS_PENDING_EXCEPTION) return; --- old/src/share/vm/logging/logTag.hpp 2016-02-22 11:00:47.080706396 -0500 +++ new/src/share/vm/logging/logTag.hpp 2016-02-22 11:00:46.989511474 -0500 @@ -66,6 +66,7 @@ LOG_TAG(phases) \ LOG_TAG(plab) \ LOG_TAG(promotion) \ + LOG_TAG(protectiondomain) /* "Trace protection domain verification" */ \ LOG_TAG(ref) \ LOG_TAG(refine) \ LOG_TAG(region) \ --- old/src/share/vm/runtime/globals.hpp 2016-02-22 11:00:47.137761283 -0500 +++ new/src/share/vm/runtime/globals.hpp 2016-02-22 11:00:46.978418569 -0500 @@ -1482,9 +1482,6 @@ develop(bool, TraceCompiledIC, false, \ "Trace changes of compiled IC") \ \ - develop(bool, TraceProtectionDomainVerification, false, \ - "Trace protection domain verification") \ - \ develop(bool, TraceClearedExceptions, false, \ "Print when an exception is forcibly cleared") \ \ --- old/src/share/vm/classfile/dictionary.cpp 2016-02-22 11:00:47.141906362 -0500 +++ new/src/share/vm/classfile/dictionary.cpp 2016-02-22 11:00:47.002396721 -0500 @@ -135,8 +135,10 @@ // via a store to _pd_set. OrderAccess::release_store_ptr(&_pd_set, new_head); } - if (TraceProtectionDomainVerification && WizardMode) { - print(); + if (log_is_enabled(Trace, protectiondomain)) { + ResourceMark rm; + outputStream* log = LogHandle(protectiondomain)::trace_stream(); + print(log); } } --- old/src/share/vm/classfile/dictionary.hpp 2016-02-22 11:00:47.143341213 -0500 +++ new/src/share/vm/classfile/dictionary.hpp 2016-02-22 11:00:47.014917159 -0500 @@ -29,6 +29,7 @@ #include "oops/instanceKlass.hpp" #include "oops/oop.hpp" #include "utilities/hashtable.hpp" +#include "utilities/ostream.hpp" class DictionaryEntry; class PSPromotionManager; @@ -323,14 +324,14 @@ return (klass->name() == class_name && _loader_data == loader_data); } - void print() { + void print(outputStream *st) { int count = 0; for (ProtectionDomainEntry* current = _pd_set; current != NULL; current = current->_next) { count++; } - tty->print_cr("pd set = #%d", count); + st->print_cr("pd set = #%d", count); } };