Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/sun/java2d/loops/GraphicsPrimitiveProxy.java
38918 views
/*1* Copyright (c) 1998, 2003, 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 sun.java2d.loops;2627/**28* GraphicsPrimitiveProxy29*30* Acts as a proxy for instances of GraphicsPrimitive, enabling lazy31* classloading of these primitives. This leads to a substantial32* savings in start-up time and footprint. In the typical case,33* it has been found that a small number of GraphicsPrimitive instance34* actually end up getting instantiated.35* <p>36* Note that the makePrimitive method should never be invoked on37* a GraphicsPrimitiveProxy object since they are instantiated as38* soon as they are found in the primitive list and never returned39* to the caller.40*/41public class GraphicsPrimitiveProxy extends GraphicsPrimitive {4243private Class owner;44private String relativeClassName;4546/**47* Create a GraphicsPrimitiveProxy for a primitive with a no-argument48* constructor.49*50* @param owner The owner class for this primitive. The primitive51* must be in the same package as this owner.52* @param relativeClassName The name of the class this is a proxy for.53* This should not include the package.54*/55public GraphicsPrimitiveProxy(Class owner, String relativeClassName,56String methodSignature,57int primID,58SurfaceType srctype,59CompositeType comptype,60SurfaceType dsttype)61{62super(methodSignature, primID, srctype, comptype, dsttype);63this.owner = owner;64this.relativeClassName = relativeClassName;65}6667public GraphicsPrimitive makePrimitive(SurfaceType srctype,68CompositeType comptype,69SurfaceType dsttype) {70// This should never happen.71throw new InternalError("makePrimitive called on a Proxy!");72}7374//75// Come up with the real instance. Called from76// GraphicsPrimitiveMgr.locate()77//78GraphicsPrimitive instantiate() {79String name = getPackageName(owner.getName()) + "."80+ relativeClassName;81try {82Class clazz = Class.forName(name);83GraphicsPrimitive p = (GraphicsPrimitive) clazz.newInstance();84if (!satisfiesSameAs(p)) {85throw new RuntimeException("Primitive " + p86+ " incompatible with proxy for "87+ name);88}89return p;90} catch (ClassNotFoundException ex) {91throw new RuntimeException(ex.toString());92} catch (InstantiationException ex) {93throw new RuntimeException(ex.toString());94} catch (IllegalAccessException ex) {95throw new RuntimeException(ex.toString());96}97// A RuntimeException should never happen in a deployed JDK, because98// the regression test GraphicsPrimitiveProxyTest will catch any99// of these errors.100}101102private static String getPackageName(String className) {103int lastDotIdx = className.lastIndexOf('.');104if (lastDotIdx < 0) {105return className;106}107return className.substring(0, lastDotIdx);108}109110public GraphicsPrimitive traceWrap() {111return instantiate().traceWrap();112}113}114115116