Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/tools/jdi/ClassLoaderReferenceImpl.java
38920 views
/*1* Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.tools.jdi;2627import com.sun.jdi.*;28import java.util.*;2930public class ClassLoaderReferenceImpl extends ObjectReferenceImpl31implements ClassLoaderReference, VMListener {3233// This is cached only while the VM is suspended34private static class Cache extends ObjectReferenceImpl.Cache {35List<ReferenceType> visibleClasses = null;36}3738protected ObjectReferenceImpl.Cache newCache() {39return new Cache();40}4142ClassLoaderReferenceImpl(VirtualMachine aVm, long ref) {43super(aVm, ref);44vm.state().addListener(this);45}4647protected String description() {48return "ClassLoaderReference " + uniqueID();49}5051public List<ReferenceType> definedClasses() {52ArrayList<ReferenceType> definedClasses = new ArrayList<ReferenceType>();53for (ReferenceType type : vm.allClasses()) {54if (type.isPrepared() &&55equals(type.classLoader())) {56definedClasses.add(type);57}58}59return definedClasses;60}6162public List<ReferenceType> visibleClasses() {63List<ReferenceType> classes = null;64try {65Cache local = (Cache)getCache();6667if (local != null) {68classes = local.visibleClasses;69}70if (classes == null) {71JDWP.ClassLoaderReference.VisibleClasses.ClassInfo[]72jdwpClasses = JDWP.ClassLoaderReference.VisibleClasses.73process(vm, this).classes;74classes = new ArrayList<ReferenceType>(jdwpClasses.length);75for (int i = 0; i < jdwpClasses.length; ++i) {76classes.add(vm.referenceType(jdwpClasses[i].typeID,77jdwpClasses[i].refTypeTag));78}79classes = Collections.unmodifiableList(classes);80if (local != null) {81local.visibleClasses = classes;82if ((vm.traceFlags & VirtualMachine.TRACE_OBJREFS) != 0) {83vm.printTrace(description() +84" temporarily caching visible classes (count = " +85classes.size() + ")");86}87}88}89} catch (JDWPException exc) {90throw exc.toJDIException();91}92return classes;93}9495Type findType(String signature) throws ClassNotLoadedException {96List<ReferenceType> types = visibleClasses();97Iterator<ReferenceType> iter = types.iterator();98while (iter.hasNext()) {99ReferenceType type = iter.next();100if (type.signature().equals(signature)) {101return type;102}103}104JNITypeParser parser = new JNITypeParser(signature);105throw new ClassNotLoadedException(parser.typeName(),106"Class " + parser.typeName() + " not loaded");107}108109byte typeValueKey() {110return JDWP.Tag.CLASS_LOADER;111}112}113114115