src/jdk/nashorn/internal/objects/NativeDebug.java

Fri, 26 Apr 2013 17:35:40 +0200

author
hannesw
date
Fri, 26 Apr 2013 17:35:40 +0200
changeset 230
c62144b08c65
parent 137
e15806b9d716
child 242
b754fb89367d
permissions
-rw-r--r--

8006559: Octane:pdfjs leaks memory, runs slower iteration to iteration
Reviewed-by: attila, sundar, jlaskey

     1 /*
     2  * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package jdk.nashorn.internal.objects;
    28 import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED;
    30 import java.io.PrintWriter;
    31 import java.util.Objects;
    32 import jdk.nashorn.internal.objects.annotations.Attribute;
    33 import jdk.nashorn.internal.objects.annotations.Function;
    34 import jdk.nashorn.internal.objects.annotations.ScriptClass;
    35 import jdk.nashorn.internal.objects.annotations.Where;
    36 import jdk.nashorn.internal.runtime.Context;
    37 import jdk.nashorn.internal.runtime.PropertyListenerManager;
    38 import jdk.nashorn.internal.runtime.PropertyMap;
    39 import jdk.nashorn.internal.runtime.ScriptFunction;
    40 import jdk.nashorn.internal.runtime.ScriptObject;
    41 import jdk.nashorn.internal.runtime.linker.LinkerCallSite;
    43 /**
    44  * Nashorn specific debug utils. This is meant for Nashorn developers.
    45  * The interface is subject to change without notice!!
    46  *
    47  */
    48 @ScriptClass("Debug")
    49 public final class NativeDebug extends ScriptObject {
    50     NativeDebug() {
    51         this.setProto(Global.objectPrototype());
    52     }
    54     @Override
    55     public String getClassName() {
    56         return "Debug";
    57     }
    59     /**
    60      * Nashorn extension: get context, context utility
    61      *
    62      * @param self self reference
    63      * @return context
    64      */
    65     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
    66     public static Object getContext(final Object self) {
    67         final SecurityManager sm = System.getSecurityManager();
    68         if (sm != null) {
    69             sm.checkPermission(new RuntimePermission("nashorn.getContext"));
    70         }
    71         return Global.getThisContext();
    72     }
    74     /**
    75      * Nashorn extension: get map from {@link ScriptObject}
    76      *
    77      * @param self self reference
    78      * @param obj script object
    79      * @return the map for the current ScriptObject
    80      */
    81     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
    82     public static Object map(final Object self, final Object obj) {
    83         if (obj instanceof ScriptObject) {
    84             return ((ScriptObject)obj).getMap();
    85         }
    86         return UNDEFINED;
    87     }
    89     /**
    90      * Nashorn extension: get embed0 from {@link ScriptObject}
    91      *
    92      * @param self self reference
    93      * @param obj script object
    94      * @return the embed0 property value for the given ScriptObject
    95      */
    96     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
    97     public static Object embed0(final Object self, final Object obj) {
    98         if (obj instanceof ScriptObject) {
    99             return ((ScriptObject)obj).embed0;
   100         }
   101         return UNDEFINED;
   102     }
   104     /**
   105      * Nashorn extension: get embed1 from {@link ScriptObject}
   106      *
   107      * @param self self reference
   108      * @param obj script object
   109      * @return the embed1 property value for the given ScriptObject
   110      */
   111     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   112     public static Object embed1(final Object self, final Object obj) {
   113         if (obj instanceof ScriptObject) {
   114             return ((ScriptObject)obj).embed1;
   115         }
   116         return UNDEFINED;
   117     }
   119     /**
   120      * Nashorn extension: get embed2 from {@link ScriptObject}
   121      *
   122      * @param self self reference
   123      * @param obj script object
   124      * @return the embed2 property value for the given ScriptObject
   125      */
   126     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   127     public static Object embed2(final Object self, final Object obj) {
   128         if (obj instanceof ScriptObject) {
   129             return ((ScriptObject)obj).embed2;
   130         }
   131         return UNDEFINED;
   132     }
   134     /**
   135      * Nashorn extension: get embed3 from {@link ScriptObject}
   136      *
   137      * @param self self reference
   138      * @param obj script object
   139      * @return the embed3 property value for the given ScriptObject
   140      */
   141     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   142     public static Object embed3(final Object self, final Object obj) {
   143         if (obj instanceof ScriptObject) {
   144             return ((ScriptObject)obj).embed3;
   145         }
   146         return UNDEFINED;
   147     }
   149     /**
   150      * Nashorn extension: get spill vector from {@link ScriptObject}
   151      *
   152      * @param self self reference
   153      * @param obj script object
   154      * @return the spill vector for the given ScriptObject
   155      */
   156     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   157     public static Object spill(final Object self, final Object obj) {
   158         if (obj instanceof ScriptObject) {
   159             return ((ScriptObject)obj).spill;
   160         }
   161         return UNDEFINED;
   162     }
   164     /**
   165      * Check object identity comparison regardless of type
   166      *
   167      * @param self self reference
   168      * @param obj1 first object in comparison
   169      * @param obj2 second object in comparison
   170      * @return true if reference identity
   171      */
   172     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   173     public static Object identical(final Object self, final Object obj1, final Object obj2) {
   174         return obj1 == obj2;
   175     }
   177     /**
   178      * Object util - getClass
   179      *
   180      * @param self self reference
   181      * @param obj  object
   182      * @return class of {@code obj}
   183      */
   184     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   185     public static Object getClass(final Object self, final Object obj) {
   186         if (obj != null) {
   187             return obj.getClass();
   188         }
   189         return UNDEFINED;
   190     }
   192     /**
   193      * Object util - equals
   194      *
   195      * @param self self reference
   196      * @param obj1 first object in comparison
   197      * @param obj2 second object in comparison
   198      * @return return {@link Object#equals(Object)} for objects.
   199      */
   200     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   201     public static Object equals(final Object self, final Object obj1, final Object obj2) {
   202         return (obj1 != null) ? obj1.equals(obj2) : false;
   203     }
   205     /**
   206      * Object util - toJavaString
   207      *
   208      * @param self self reference
   209      * @param obj  object to represent as a string
   210      * @return Java string representation of {@code obj}
   211      */
   212     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   213     public static Object toJavaString(final Object self, final Object obj) {
   214         return Objects.toString(obj);
   215     }
   217     /**
   218      * Do not call overridden toString -- use default toString impl
   219      *
   220      * @param self self reference
   221      * @param obj  object to represent as a string
   222      * @return string representation
   223      */
   224     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   225     public static Object toIdentString(final Object self, final Object obj) {
   226         if (obj == null) {
   227             return "null";
   228         }
   230         final int hash = System.identityHashCode(obj);
   231         return obj.getClass() + "@" + Integer.toHexString(hash);
   232     }
   234     /**
   235      * Dump all Nashorn debug mode counters. Calling this may be better if
   236      * you want to print all counters. This way you can avoid too many callsites
   237      * due to counter access itself!!
   238      * @param self self reference
   239      * @return undefined
   240      */
   241     @SuppressWarnings("resource")
   242     @Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
   243     public static Object dumpCounters(final Object self) {
   244         final PrintWriter out = Context.getCurrentErr();
   246         out.println("ScriptObject count " + ScriptObject.getCount());
   247         out.println("Scope count " + ScriptObject.getScopeCount());
   248         out.println("ScriptObject listeners added " + PropertyListenerManager.getListenersAdded());
   249         out.println("ScriptObject listeners removed " + PropertyListenerManager.getListenersRemoved());
   250         out.println("ScriptFunction count " + ScriptObject.getCount());
   251         out.println("ScriptFunction invokes " + ScriptFunction.getInvokes());
   252         out.println("ScriptFunction allocations " + ScriptFunction.getAllocations());
   253         out.println("PropertyMap count " + PropertyMap.getCount());
   254         out.println("PropertyMap cloned " + PropertyMap.getClonedCount());
   255         out.println("PropertyMap history hit " + PropertyMap.getHistoryHit());
   256         out.println("PropertyMap proto invalidations " + PropertyMap.getProtoInvalidations());
   257         out.println("PropertyMap proto history hit " + PropertyMap.getProtoHistoryHit());
   258         out.println("PropertyMap setProtoNewMapCount " + PropertyMap.getSetProtoNewMapCount());
   259         out.println("Callsite count " + LinkerCallSite.getCount());
   260         out.println("Callsite misses " + LinkerCallSite.getMissCount());
   261         out.println("Callsite misses by site at " + LinkerCallSite.getMissSamplingPercentage() + "%");
   263         LinkerCallSite.getMissCounts(out);
   265         return UNDEFINED;
   266     }
   267 }

mercurial