001package Torello.Browser;
002
003import java.util.*;
004import javax.json.*;
005import javax.json.stream.*;
006import java.io.*;
007
008import java.lang.reflect.Method;
009import java.lang.reflect.Parameter;
010import java.util.function.Function;
011
012import Torello.Java.Additional.*;
013import Torello.Java.JSON.*;
014
015import static Torello.Java.JSON.JFlag.*;
016
017import Torello.Java.StrCmpr;
018import Torello.JavaDoc.StaticFunctional;
019import Torello.JavaDoc.JDHeaderBackgroundImg;
020import Torello.JavaDoc.Excuse;
021
022/**
023 * <SPAN CLASS=COPIEDJDK><B><CODE>[No Description Provided by Google]</CODE></B></SPAN>
024 * 
025 * <EMBED CLASS='external-html' DATA-FILE-ID=CODE_GEN_NOTE>
026 */
027@StaticFunctional(Excused={"counter"}, Excuses={Excuse.CONFIGURATION})
028@JDHeaderBackgroundImg(EmbedTagFileID="WOOD_PLANK_NOTE")
029public class HeapProfiler
030{
031    // ********************************************************************************************
032    // ********************************************************************************************
033    // Class Header Stuff
034    // ********************************************************************************************
035    // ********************************************************************************************
036
037
038    // No Pubic Constructors
039    private HeapProfiler () { }
040
041    // These two Vector's are used by all the "Methods" exported by this class.  java.lang.reflect
042    // is used to generate the JSON String's.  It saves thousands of lines of Auto-Generated Code.
043    private static final Map<String, Vector<String>>    parameterNames = new HashMap<>();
044    private static final Map<String, Vector<Class<?>>>  parameterTypes = new HashMap<>();
045
046    // Some Methods do not take any parameters - for instance all the "enable()" and "disable()"
047    // I simply could not get ride of RAW-TYPES and UNCHECKED warnings... so there are now,
048    // offically, two empty-vectors.  One for String's, and the other for Classes.
049
050    private static final Vector<String>     EMPTY_VEC_STR = new Vector<>();
051    private static final Vector<Class<?>>   EMPTY_VEC_CLASS = new Vector<>();
052
053    static
054    {
055        for (Method m : HeapProfiler.class.getMethods())
056        {
057            // This doesn't work!  The parameter names are all "arg0" ... "argN"
058            // It works for java.lang.reflect.Field, BUT NOT java.lang.reflect.Parameter!
059            //
060            // Vector<String> parameterNamesList = new Vector<>(); -- NOPE!
061
062            Vector<Class<?>> parameterTypesList = new Vector<>();
063        
064            for (Parameter p : m.getParameters()) parameterTypesList.add(p.getType());
065
066            parameterTypes.put(
067                m.getName(),
068                (parameterTypesList.size() > 0) ? parameterTypesList : EMPTY_VEC_CLASS
069            );
070        }
071    }
072
073    static
074    {
075        Vector<String> v = null;
076
077        v = new Vector<String>(1);
078        parameterNames.put("addInspectedHeapObject", v);
079        Collections.addAll(v, new String[]
080        { "heapObjectId", });
081
082        parameterNames.put("collectGarbage", EMPTY_VEC_STR);
083
084        parameterNames.put("disable", EMPTY_VEC_STR);
085
086        parameterNames.put("enable", EMPTY_VEC_STR);
087
088        v = new Vector<String>(1);
089        parameterNames.put("getHeapObjectId", v);
090        Collections.addAll(v, new String[]
091        { "objectId", });
092
093        v = new Vector<String>(2);
094        parameterNames.put("getObjectByHeapObjectId", v);
095        Collections.addAll(v, new String[]
096        { "objectId", "objectGroup", });
097
098        parameterNames.put("getSamplingProfile", EMPTY_VEC_STR);
099
100        v = new Vector<String>(1);
101        parameterNames.put("startSampling", v);
102        Collections.addAll(v, new String[]
103        { "samplingInterval", });
104
105        v = new Vector<String>(1);
106        parameterNames.put("startTrackingHeapObjects", v);
107        Collections.addAll(v, new String[]
108        { "trackAllocations", });
109
110        parameterNames.put("stopSampling", EMPTY_VEC_STR);
111
112        v = new Vector<String>(3);
113        parameterNames.put("stopTrackingHeapObjects", v);
114        Collections.addAll(v, new String[]
115        { "reportProgress", "treatGlobalObjectsAsRoots", "captureNumericValue", });
116
117        v = new Vector<String>(3);
118        parameterNames.put("takeHeapSnapshot", v);
119        Collections.addAll(v, new String[]
120        { "reportProgress", "treatGlobalObjectsAsRoots", "captureNumericValue", });
121    }
122
123
124    // ********************************************************************************************
125    // ********************************************************************************************
126    // Types - Static Inner Classes
127    // ********************************************************************************************
128    // ********************************************************************************************
129
130    // public static class HeapSnapshotObjectId => String
131    
132    /** Sampling Heap Profile node. Holds callsite information, allocation statistics and child nodes. */
133    public static class SamplingHeapProfileNode
134        extends BaseType
135        implements java.io.Serializable
136    {
137        /** For Object Serialization.  java.io.Serializable */
138        protected static final long serialVersionUID = 1;
139        
140        public boolean[] optionals()
141        { return new boolean[] { false, false, false, false, }; }
142        
143        /** Function location. */
144        public final RunTime.CallFrame callFrame;
145        
146        /** Allocations size in bytes for the node excluding children. */
147        public final Number selfSize;
148        
149        /** Node id. Ids are unique across all profiles collected between startSampling and stopSampling. */
150        public final int id;
151        
152        /** Child nodes. */
153        public final HeapProfiler.SamplingHeapProfileNode[] children;
154        
155        /**
156         * Constructor
157         *
158         * @param callFrame Function location.
159         * 
160         * @param selfSize Allocations size in bytes for the node excluding children.
161         * 
162         * @param id Node id. Ids are unique across all profiles collected between startSampling and stopSampling.
163         * 
164         * @param children Child nodes.
165         */
166        public SamplingHeapProfileNode(
167                RunTime.CallFrame callFrame, Number selfSize, int id, 
168                HeapProfiler.SamplingHeapProfileNode[] children
169            )
170        {
171            // Exception-Check(s) to ensure that if any parameters which are not declared as
172            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
173            
174            if (callFrame == null) BRDPC.throwNPE("callFrame");
175            if (selfSize == null)  BRDPC.throwNPE("selfSize");
176            if (children == null)  BRDPC.throwNPE("children");
177            
178            this.callFrame  = callFrame;
179            this.selfSize   = selfSize;
180            this.id         = id;
181            this.children   = children;
182        }
183        
184        /**
185         * JSON Object Constructor
186         * @param jo A Json-Object having data about an instance of {@code 'SamplingHeapProfileNode'}.
187         */
188        public SamplingHeapProfileNode (JsonObject jo)
189        {
190            this.callFrame  = ReadJSON.getObject(jo, "callFrame", RunTime.CallFrame.class, false, true);
191            this.selfSize   = ReadNumberJSON.get(jo, "selfSize", false, true);
192            this.id         = ReadPrimJSON.getInt(jo, "id");
193            this.children = (jo.getJsonArray("children") == null)
194                ? null
195                : ReadArrJSON.DimN.objArr(jo.getJsonArray("children"), null, 0, HeapProfiler.SamplingHeapProfileNode[].class);
196        
197        }
198        
199        
200        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
201        public boolean equals(Object other)
202        {
203            if (other == null)                       return false;
204            if (other.getClass() != this.getClass()) return false;
205        
206            SamplingHeapProfileNode o = (SamplingHeapProfileNode) other;
207        
208            return
209                    Objects.equals(this.callFrame, o.callFrame)
210                &&  Objects.equals(this.selfSize, o.selfSize)
211                &&  (this.id == o.id)
212                &&  Arrays.deepEquals(this.children, o.children);
213        }
214        
215        /** Generates a Hash-Code for {@code 'this'} instance */
216        public int hashCode()
217        {
218            return
219                    this.callFrame.hashCode()
220                +   Objects.hashCode(this.selfSize)
221                +   this.id
222                +   Arrays.deepHashCode(this.children);
223        }
224    }
225    
226    /** A single sample from a sampling profile. */
227    public static class SamplingHeapProfileSample
228        extends BaseType
229        implements java.io.Serializable
230    {
231        /** For Object Serialization.  java.io.Serializable */
232        protected static final long serialVersionUID = 1;
233        
234        public boolean[] optionals()
235        { return new boolean[] { false, false, false, }; }
236        
237        /** Allocation size in bytes attributed to the sample. */
238        public final Number size;
239        
240        /** Id of the corresponding profile tree node. */
241        public final int nodeId;
242        
243        /**
244         * Time-ordered sample ordinal number. It is unique across all profiles retrieved
245         * between startSampling and stopSampling.
246         */
247        public final Number ordinal;
248        
249        /**
250         * Constructor
251         *
252         * @param size Allocation size in bytes attributed to the sample.
253         * 
254         * @param nodeId Id of the corresponding profile tree node.
255         * 
256         * @param ordinal 
257         * Time-ordered sample ordinal number. It is unique across all profiles retrieved
258         * between startSampling and stopSampling.
259         */
260        public SamplingHeapProfileSample(Number size, int nodeId, Number ordinal)
261        {
262            // Exception-Check(s) to ensure that if any parameters which are not declared as
263            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
264            
265            if (size == null)    BRDPC.throwNPE("size");
266            if (ordinal == null) BRDPC.throwNPE("ordinal");
267            
268            this.size     = size;
269            this.nodeId   = nodeId;
270            this.ordinal  = ordinal;
271        }
272        
273        /**
274         * JSON Object Constructor
275         * @param jo A Json-Object having data about an instance of {@code 'SamplingHeapProfileSample'}.
276         */
277        public SamplingHeapProfileSample (JsonObject jo)
278        {
279            this.size     = ReadNumberJSON.get(jo, "size", false, true);
280            this.nodeId   = ReadPrimJSON.getInt(jo, "nodeId");
281            this.ordinal  = ReadNumberJSON.get(jo, "ordinal", false, true);
282        }
283        
284        
285        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
286        public boolean equals(Object other)
287        {
288            if (other == null)                       return false;
289            if (other.getClass() != this.getClass()) return false;
290        
291            SamplingHeapProfileSample o = (SamplingHeapProfileSample) other;
292        
293            return
294                    Objects.equals(this.size, o.size)
295                &&  (this.nodeId == o.nodeId)
296                &&  Objects.equals(this.ordinal, o.ordinal);
297        }
298        
299        /** Generates a Hash-Code for {@code 'this'} instance */
300        public int hashCode()
301        {
302            return
303                    Objects.hashCode(this.size)
304                +   this.nodeId
305                +   Objects.hashCode(this.ordinal);
306        }
307    }
308    
309    /** Sampling profile. */
310    public static class SamplingHeapProfile
311        extends BaseType
312        implements java.io.Serializable
313    {
314        /** For Object Serialization.  java.io.Serializable */
315        protected static final long serialVersionUID = 1;
316        
317        public boolean[] optionals()
318        { return new boolean[] { false, false, }; }
319        
320        /** <CODE>[No Description Provided by Google]</CODE> */
321        public final HeapProfiler.SamplingHeapProfileNode head;
322        
323        /** <CODE>[No Description Provided by Google]</CODE> */
324        public final HeapProfiler.SamplingHeapProfileSample[] samples;
325        
326        /**
327         * Constructor
328         *
329         * @param head -
330         * 
331         * @param samples -
332         */
333        public SamplingHeapProfile(
334                HeapProfiler.SamplingHeapProfileNode head, 
335                HeapProfiler.SamplingHeapProfileSample[] samples
336            )
337        {
338            // Exception-Check(s) to ensure that if any parameters which are not declared as
339            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
340            
341            if (head == null)    BRDPC.throwNPE("head");
342            if (samples == null) BRDPC.throwNPE("samples");
343            
344            this.head     = head;
345            this.samples  = samples;
346        }
347        
348        /**
349         * JSON Object Constructor
350         * @param jo A Json-Object having data about an instance of {@code 'SamplingHeapProfile'}.
351         */
352        public SamplingHeapProfile (JsonObject jo)
353        {
354            this.head     = ReadJSON.getObject(jo, "head", HeapProfiler.SamplingHeapProfileNode.class, false, true);
355            this.samples = (jo.getJsonArray("samples") == null)
356                ? null
357                : ReadArrJSON.DimN.objArr(jo.getJsonArray("samples"), null, 0, HeapProfiler.SamplingHeapProfileSample[].class);
358        
359        }
360        
361        
362        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
363        public boolean equals(Object other)
364        {
365            if (other == null)                       return false;
366            if (other.getClass() != this.getClass()) return false;
367        
368            SamplingHeapProfile o = (SamplingHeapProfile) other;
369        
370            return
371                    Objects.equals(this.head, o.head)
372                &&  Arrays.deepEquals(this.samples, o.samples);
373        }
374        
375        /** Generates a Hash-Code for {@code 'this'} instance */
376        public int hashCode()
377        {
378            return
379                    this.head.hashCode()
380                +   Arrays.deepHashCode(this.samples);
381        }
382    }
383    
384    /**
385     * -
386     *
387     * <BR /><BR />This is Marker-Event.  Marker-Event's are Events that do not posses
388     * any data, fields or state.  When they are fired, only the event name is supplied.
389     */
390    public static class resetProfiles
391        extends BrowserEvent
392        implements java.io.Serializable
393    {
394        /** For Object Serialization.  java.io.Serializable */
395        protected static final long serialVersionUID = 1;
396    
397        public boolean[] optionals() { return new boolean[0]; }
398    
399        /** JSON Object Constructor */
400        public resetProfiles(JsonObject jo)
401        { super("HeapProfiler", "resetProfiles", 0); }
402    
403        @Override
404        public String toString() { return "HeapProfiler.resetProfiles Marker Event\n"; }
405    }
406    
407    /** <CODE>[No Description Provided by Google]</CODE> */
408    public static class addHeapSnapshotChunk
409        extends BrowserEvent
410        implements java.io.Serializable
411    {
412        /** For Object Serialization.  java.io.Serializable */
413        protected static final long serialVersionUID = 1;
414        
415        public boolean[] optionals()
416        { return new boolean[] { false, }; }
417        
418        /** <CODE>[No Description Provided by Google]</CODE> */
419        public final String chunk;
420        
421        /**
422         * Constructor
423         *
424         * @param chunk -
425         */
426        public addHeapSnapshotChunk(String chunk)
427        {
428            super("HeapProfiler", "addHeapSnapshotChunk", 1);
429            
430            // Exception-Check(s) to ensure that if any parameters which are not declared as
431            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
432            
433            if (chunk == null) BRDPC.throwNPE("chunk");
434            
435            this.chunk  = chunk;
436        }
437        
438        /**
439         * JSON Object Constructor
440         * @param jo A Json-Object having data about an instance of {@code 'addHeapSnapshotChunk'}.
441         */
442        public addHeapSnapshotChunk (JsonObject jo)
443        {
444            super("HeapProfiler", "addHeapSnapshotChunk", 1);
445        
446            this.chunk  = ReadJSON.getString(jo, "chunk", false, true);
447        }
448        
449        
450        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
451        public boolean equals(Object other)
452        {
453            if (other == null)                       return false;
454            if (other.getClass() != this.getClass()) return false;
455        
456            addHeapSnapshotChunk o = (addHeapSnapshotChunk) other;
457        
458            return
459                    Objects.equals(this.chunk, o.chunk);
460        }
461        
462        /** Generates a Hash-Code for {@code 'this'} instance */
463        public int hashCode()
464        {
465            return
466                    Objects.hashCode(this.chunk);
467        }
468    }
469    
470    /** If heap objects tracking has been started then backend may send update for one or more fragments */
471    public static class heapStatsUpdate
472        extends BrowserEvent
473        implements java.io.Serializable
474    {
475        /** For Object Serialization.  java.io.Serializable */
476        protected static final long serialVersionUID = 1;
477        
478        public boolean[] optionals()
479        { return new boolean[] { false, }; }
480        
481        /**
482         * An array of triplets. Each triplet describes a fragment. The first integer is the fragment
483         * index, the second integer is a total count of objects for the fragment, the third integer is
484         * a total size of the objects for the fragment.
485         */
486        public final int[] statsUpdate;
487        
488        /**
489         * Constructor
490         *
491         * @param statsUpdate 
492         * An array of triplets. Each triplet describes a fragment. The first integer is the fragment
493         * index, the second integer is a total count of objects for the fragment, the third integer is
494         * a total size of the objects for the fragment.
495         */
496        public heapStatsUpdate(int[] statsUpdate)
497        {
498            super("HeapProfiler", "heapStatsUpdate", 1);
499            
500            // Exception-Check(s) to ensure that if any parameters which are not declared as
501            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
502            
503            if (statsUpdate == null) BRDPC.throwNPE("statsUpdate");
504            
505            this.statsUpdate  = statsUpdate;
506        }
507        
508        /**
509         * JSON Object Constructor
510         * @param jo A Json-Object having data about an instance of {@code 'heapStatsUpdate'}.
511         */
512        public heapStatsUpdate (JsonObject jo)
513        {
514            super("HeapProfiler", "heapStatsUpdate", 1);
515        
516            this.statsUpdate = (jo.getJsonArray("statsUpdate") == null)
517                ? null
518                : ReadArrJSON.DimN.intArr(jo.getJsonArray("statsUpdate"), -1, 0, null, int[].class);
519        
520        }
521        
522        
523        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
524        public boolean equals(Object other)
525        {
526            if (other == null)                       return false;
527            if (other.getClass() != this.getClass()) return false;
528        
529            heapStatsUpdate o = (heapStatsUpdate) other;
530        
531            return
532                    Arrays.equals(this.statsUpdate, o.statsUpdate);
533        }
534        
535        /** Generates a Hash-Code for {@code 'this'} instance */
536        public int hashCode()
537        {
538            return
539                    Arrays.hashCode(this.statsUpdate);
540        }
541    }
542    
543    /**
544     * If heap objects tracking has been started then backend regularly sends a current value for last
545     * seen object id and corresponding timestamp. If the were changes in the heap since last event
546     * then one or more heapStatsUpdate events will be sent before a new lastSeenObjectId event.
547     */
548    public static class lastSeenObjectId
549        extends BrowserEvent
550        implements java.io.Serializable
551    {
552        /** For Object Serialization.  java.io.Serializable */
553        protected static final long serialVersionUID = 1;
554        
555        public boolean[] optionals()
556        { return new boolean[] { false, false, }; }
557        
558        /** <CODE>[No Description Provided by Google]</CODE> */
559        public final int lastSeenObjectId;
560        
561        /** <CODE>[No Description Provided by Google]</CODE> */
562        public final Number timestamp;
563        
564        /**
565         * Constructor
566         *
567         * @param lastSeenObjectId -
568         * 
569         * @param timestamp -
570         */
571        public lastSeenObjectId(int lastSeenObjectId, Number timestamp)
572        {
573            super("HeapProfiler", "lastSeenObjectId", 2);
574            
575            // Exception-Check(s) to ensure that if any parameters which are not declared as
576            // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
577            
578            if (timestamp == null) BRDPC.throwNPE("timestamp");
579            
580            this.lastSeenObjectId  = lastSeenObjectId;
581            this.timestamp         = timestamp;
582        }
583        
584        /**
585         * JSON Object Constructor
586         * @param jo A Json-Object having data about an instance of {@code 'lastSeenObjectId'}.
587         */
588        public lastSeenObjectId (JsonObject jo)
589        {
590            super("HeapProfiler", "lastSeenObjectId", 2);
591        
592            this.lastSeenObjectId  = ReadPrimJSON.getInt(jo, "lastSeenObjectId");
593            this.timestamp         = ReadNumberJSON.get(jo, "timestamp", false, true);
594        }
595        
596        
597        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
598        public boolean equals(Object other)
599        {
600            if (other == null)                       return false;
601            if (other.getClass() != this.getClass()) return false;
602        
603            lastSeenObjectId o = (lastSeenObjectId) other;
604        
605            return
606                    (this.lastSeenObjectId == o.lastSeenObjectId)
607                &&  Objects.equals(this.timestamp, o.timestamp);
608        }
609        
610        /** Generates a Hash-Code for {@code 'this'} instance */
611        public int hashCode()
612        {
613            return
614                    this.lastSeenObjectId
615                +   Objects.hashCode(this.timestamp);
616        }
617    }
618    
619    /** <CODE>[No Description Provided by Google]</CODE> */
620    public static class reportHeapSnapshotProgress
621        extends BrowserEvent
622        implements java.io.Serializable
623    {
624        /** For Object Serialization.  java.io.Serializable */
625        protected static final long serialVersionUID = 1;
626        
627        public boolean[] optionals()
628        { return new boolean[] { false, false, true, }; }
629        
630        /** <CODE>[No Description Provided by Google]</CODE> */
631        public final int done;
632        
633        /** <CODE>[No Description Provided by Google]</CODE> */
634        public final int total;
635        
636        /**
637         * <CODE>[No Description Provided by Google]</CODE>
638         * <BR />
639         * <BR /><B>OPTIONAL</B>
640         */
641        public final Boolean finished;
642        
643        /**
644         * Constructor
645         *
646         * @param done -
647         * 
648         * @param total -
649         * 
650         * @param finished -
651         * <BR /><B>OPTIONAL</B>
652         */
653        public reportHeapSnapshotProgress(int done, int total, Boolean finished)
654        {
655            super("HeapProfiler", "reportHeapSnapshotProgress", 3);
656            
657            this.done      = done;
658            this.total     = total;
659            this.finished  = finished;
660        }
661        
662        /**
663         * JSON Object Constructor
664         * @param jo A Json-Object having data about an instance of {@code 'reportHeapSnapshotProgress'}.
665         */
666        public reportHeapSnapshotProgress (JsonObject jo)
667        {
668            super("HeapProfiler", "reportHeapSnapshotProgress", 3);
669        
670            this.done      = ReadPrimJSON.getInt(jo, "done");
671            this.total     = ReadPrimJSON.getInt(jo, "total");
672            this.finished  = ReadBoxedJSON.getBoolean(jo, "finished", true);
673        }
674        
675        
676        /** Checks whether {@code 'this'} equals an input Java-{@code Object} */
677        public boolean equals(Object other)
678        {
679            if (other == null)                       return false;
680            if (other.getClass() != this.getClass()) return false;
681        
682            reportHeapSnapshotProgress o = (reportHeapSnapshotProgress) other;
683        
684            return
685                    (this.done == o.done)
686                &&  (this.total == o.total)
687                &&  Objects.equals(this.finished, o.finished);
688        }
689        
690        /** Generates a Hash-Code for {@code 'this'} instance */
691        public int hashCode()
692        {
693            return
694                    this.done
695                +   this.total
696                +   Objects.hashCode(this.finished);
697        }
698    }
699    
700    
701    // Counter for keeping the WebSocket Request ID's distinct.
702    private static int counter = 1;
703    
704    /**
705     * Enables console to refer to the node with given id via $x (see Command Line API for more details
706     * $x functions).
707     * 
708     * @param heapObjectId Heap snapshot object id to be accessible by means of $x command line API.
709     * 
710     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
711     * {@link Ret0}&gt;</CODE>
712     *
713     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
714     * browser receives the invocation-request.
715     *
716     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
717     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
718     * {@code >} to ensure the Browser Function has run to completion.
719     */
720    public static Script<String, JsonObject, Ret0> addInspectedHeapObject(String heapObjectId)
721    {
722        // Exception-Check(s) to ensure that if any parameters which are not declared as
723        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
724        
725        if (heapObjectId == null) BRDPC.throwNPE("heapObjectId");
726        
727        final int       webSocketID = 3000000 + counter++;
728        final boolean[] optionals   = { false, };
729        
730        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
731        String requestJSON = WriteJSON.get(
732            parameterTypes.get("addInspectedHeapObject"),
733            parameterNames.get("addInspectedHeapObject"),
734            optionals, webSocketID,
735            "HeapProfiler.addInspectedHeapObject",
736            heapObjectId
737        );
738        
739        // This Remote Command does not have a Return-Value.
740        return new Script<>
741            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
742    }
743    
744    /**
745     * <CODE>[No Description Provided by Google]</CODE>
746     * 
747     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
748     * {@link Ret0}&gt;</CODE>
749     *
750     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
751     * browser receives the invocation-request.
752     *
753     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
754     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
755     * {@code >} to ensure the Browser Function has run to completion.
756     */
757    public static Script<String, JsonObject, Ret0> collectGarbage()
758    {
759        final int          webSocketID = 3001000 + counter++;
760        final boolean[]    optionals   = new boolean[0];
761        
762        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
763        String requestJSON = WriteJSON.get(
764            parameterTypes.get("collectGarbage"),
765            parameterNames.get("collectGarbage"),
766            optionals, webSocketID,
767            "HeapProfiler.collectGarbage"
768        );
769        
770        // This Remote Command does not have a Return-Value.
771        return new Script<>
772            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
773    }
774    
775    /**
776     * <CODE>[No Description Provided by Google]</CODE>
777     * 
778     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
779     * {@link Ret0}&gt;</CODE>
780     *
781     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
782     * browser receives the invocation-request.
783     *
784     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
785     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
786     * {@code >} to ensure the Browser Function has run to completion.
787     */
788    public static Script<String, JsonObject, Ret0> disable()
789    {
790        final int          webSocketID = 3002000 + counter++;
791        final boolean[]    optionals   = new boolean[0];
792        
793        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
794        String requestJSON = WriteJSON.get(
795            parameterTypes.get("disable"),
796            parameterNames.get("disable"),
797            optionals, webSocketID,
798            "HeapProfiler.disable"
799        );
800        
801        // This Remote Command does not have a Return-Value.
802        return new Script<>
803            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
804    }
805    
806    /**
807     * <CODE>[No Description Provided by Google]</CODE>
808     * 
809     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
810     * {@link Ret0}&gt;</CODE>
811     *
812     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
813     * browser receives the invocation-request.
814     *
815     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
816     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
817     * {@code >} to ensure the Browser Function has run to completion.
818     */
819    public static Script<String, JsonObject, Ret0> enable()
820    {
821        final int          webSocketID = 3003000 + counter++;
822        final boolean[]    optionals   = new boolean[0];
823        
824        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
825        String requestJSON = WriteJSON.get(
826            parameterTypes.get("enable"),
827            parameterNames.get("enable"),
828            optionals, webSocketID,
829            "HeapProfiler.enable"
830        );
831        
832        // This Remote Command does not have a Return-Value.
833        return new Script<>
834            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
835    }
836    
837    /**
838     * <CODE>[No Description Provided by Google]</CODE>
839     * 
840     * @param objectId Identifier of the object to get heap object id for.
841     * 
842     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
843     * String&gt;</CODE>
844     * 
845     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
846     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
847     * String&gt;</CODE> will be returned.
848     *
849     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
850     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
851      * may be retrieved.</I>
852     *
853     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
854     * <BR /><BR /><UL CLASS=JDUL>
855     * <LI><CODE>String (<B>heapSnapshotObjectId</B></CODE>)
856     *     <BR />Id of the heap snapshot object corresponding to the passed remote object id.
857     * </LI>
858     * </UL> */
859    public static Script<String, JsonObject, String> getHeapObjectId(String objectId)
860    {
861        // Exception-Check(s) to ensure that if any parameters which are not declared as
862        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
863        
864        if (objectId == null) BRDPC.throwNPE("objectId");
865        
866        final int       webSocketID = 3004000 + counter++;
867        final boolean[] optionals   = { false, };
868        
869        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
870        String requestJSON = WriteJSON.get(
871            parameterTypes.get("getHeapObjectId"),
872            parameterNames.get("getHeapObjectId"),
873            optionals, webSocketID,
874            "HeapProfiler.getHeapObjectId",
875            objectId
876        );
877        
878        // 'JSON Binding' ... Converts Browser Response-JSON to 'String'
879        Function<JsonObject, String> responseProcessor = (JsonObject jo) ->
880            ReadJSON.getString(jo, "heapSnapshotObjectId", false, true);
881        
882        // Pass the 'defaultSender' to Script-Constructor
883        // The sender that is used can be changed before executing script.
884        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
885    }
886    
887    /**
888     * <CODE>[No Description Provided by Google]</CODE>
889     * 
890     * @param objectId -
891     * 
892     * @param objectGroup Symbolic group name that can be used to release multiple objects.
893     * <BR /><B>OPTIONAL</B>
894     * 
895     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
896     * {@link RunTime.RemoteObject}&gt;</CODE>
897     * 
898     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
899     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
900     * {@link RunTime.RemoteObject}&gt;</CODE> will be returned.
901     *
902     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
903     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
904      * may be retrieved.</I>
905     *
906     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
907     * <BR /><BR /><UL CLASS=JDUL>
908     * <LI><CODE>{@link RunTime.RemoteObject} (<B>result</B></CODE>)
909     *     <BR />Evaluation result.
910     * </LI>
911     * </UL> */
912    public static Script<String, JsonObject, RunTime.RemoteObject> getObjectByHeapObjectId
913        (String objectId, String objectGroup)
914    {
915        // Exception-Check(s) to ensure that if any parameters which are not declared as
916        // 'Optional', but have a 'null' value anyway, that a NullPointerException shall throw.
917        
918        if (objectId == null) BRDPC.throwNPE("objectId");
919        
920        final int       webSocketID = 3005000 + counter++;
921        final boolean[] optionals   = { false, true, };
922        
923        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
924        String requestJSON = WriteJSON.get(
925            parameterTypes.get("getObjectByHeapObjectId"),
926            parameterNames.get("getObjectByHeapObjectId"),
927            optionals, webSocketID,
928            "HeapProfiler.getObjectByHeapObjectId",
929            objectId, objectGroup
930        );
931        
932        // 'JSON Binding' ... Converts Browser Response-JSON to 'RunTime.RemoteObject'
933        Function<JsonObject, RunTime.RemoteObject> responseProcessor = (JsonObject jo) ->
934            ReadJSON.getObject(jo, "result", RunTime.RemoteObject.class, false, true);
935        
936        // Pass the 'defaultSender' to Script-Constructor
937        // The sender that is used can be changed before executing script.
938        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
939    }
940    
941    /**
942     * <CODE>[No Description Provided by Google]</CODE>
943     * 
944     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
945     * {@link HeapProfiler.SamplingHeapProfile}&gt;</CODE>
946     * 
947     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
948     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
949     * {@link HeapProfiler.SamplingHeapProfile}&gt;</CODE> will be returned.
950     *
951     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
952     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
953      * may be retrieved.</I>
954     *
955     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
956     * <BR /><BR /><UL CLASS=JDUL>
957     * <LI><CODE>{@link HeapProfiler.SamplingHeapProfile} (<B>profile</B></CODE>)
958     *     <BR />Return the sampling profile being collected.
959     * </LI>
960     * </UL> */
961    public static Script<String, JsonObject, HeapProfiler.SamplingHeapProfile> getSamplingProfile()
962    {
963        final int          webSocketID = 3006000 + counter++;
964        final boolean[]    optionals   = new boolean[0];
965        
966        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
967        String requestJSON = WriteJSON.get(
968            parameterTypes.get("getSamplingProfile"),
969            parameterNames.get("getSamplingProfile"),
970            optionals, webSocketID,
971            "HeapProfiler.getSamplingProfile"
972        );
973        
974        // 'JSON Binding' ... Converts Browser Response-JSON to 'HeapProfiler.SamplingHeapProfile'
975        Function<JsonObject, HeapProfiler.SamplingHeapProfile> responseProcessor = (JsonObject jo) ->
976            ReadJSON.getObject(jo, "profile", HeapProfiler.SamplingHeapProfile.class, false, true);
977        
978        // Pass the 'defaultSender' to Script-Constructor
979        // The sender that is used can be changed before executing script.
980        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
981    }
982    
983    /**
984     * <CODE>[No Description Provided by Google]</CODE>
985     * 
986     * @param samplingInterval 
987     * Average sample interval in bytes. Poisson distribution is used for the intervals. The
988     * default value is 32768 bytes.
989     * <BR /><B>OPTIONAL</B>
990     * 
991     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
992     * {@link Ret0}&gt;</CODE>
993     *
994     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
995     * browser receives the invocation-request.
996     *
997     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
998     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
999     * {@code >} to ensure the Browser Function has run to completion.
1000     */
1001    public static Script<String, JsonObject, Ret0> startSampling(Number samplingInterval)
1002    {
1003        final int       webSocketID = 3007000 + counter++;
1004        final boolean[] optionals   = { true, };
1005        
1006        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1007        String requestJSON = WriteJSON.get(
1008            parameterTypes.get("startSampling"),
1009            parameterNames.get("startSampling"),
1010            optionals, webSocketID,
1011            "HeapProfiler.startSampling",
1012            samplingInterval
1013        );
1014        
1015        // This Remote Command does not have a Return-Value.
1016        return new Script<>
1017            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1018    }
1019    
1020    /**
1021     * <CODE>[No Description Provided by Google]</CODE>
1022     * 
1023     * @param trackAllocations -
1024     * <BR /><B>OPTIONAL</B>
1025     * 
1026     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1027     * {@link Ret0}&gt;</CODE>
1028     *
1029     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1030     * browser receives the invocation-request.
1031     *
1032     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1033     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1034     * {@code >} to ensure the Browser Function has run to completion.
1035     */
1036    public static Script<String, JsonObject, Ret0> startTrackingHeapObjects
1037        (Boolean trackAllocations)
1038    {
1039        final int       webSocketID = 3008000 + counter++;
1040        final boolean[] optionals   = { true, };
1041        
1042        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1043        String requestJSON = WriteJSON.get(
1044            parameterTypes.get("startTrackingHeapObjects"),
1045            parameterNames.get("startTrackingHeapObjects"),
1046            optionals, webSocketID,
1047            "HeapProfiler.startTrackingHeapObjects",
1048            trackAllocations
1049        );
1050        
1051        // This Remote Command does not have a Return-Value.
1052        return new Script<>
1053            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1054    }
1055    
1056    /**
1057     * <CODE>[No Description Provided by Google]</CODE>
1058     * 
1059     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1060     * {@link HeapProfiler.SamplingHeapProfile}&gt;</CODE>
1061     * 
1062     * <BR /><BR />This <B>script</B> may be <B STYLE='color: red'>executed</B>, using
1063     * {@link Script#exec()}, and afterwards, a {@link Promise}<CODE>&lt;JsonObject,
1064     * {@link HeapProfiler.SamplingHeapProfile}&gt;</CODE> will be returned.
1065     *
1066     * <BR /><BR />Finally, the <B>{@code Promise}</B> may be <B STYLE='color: red'>awaited</B>,
1067     * using {@link Promise#await()}, <I>and the returned result of this Browser Function may
1068      * may be retrieved.</I>
1069     *
1070     * <BR /><BR />This Browser Function <B STYLE='color: red'>returns</B>
1071     * <BR /><BR /><UL CLASS=JDUL>
1072     * <LI><CODE>{@link HeapProfiler.SamplingHeapProfile} (<B>profile</B></CODE>)
1073     *     <BR />Recorded sampling heap profile.
1074     * </LI>
1075     * </UL> */
1076    public static Script<String, JsonObject, HeapProfiler.SamplingHeapProfile> stopSampling()
1077    {
1078        final int          webSocketID = 3009000 + counter++;
1079        final boolean[]    optionals   = new boolean[0];
1080        
1081        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1082        String requestJSON = WriteJSON.get(
1083            parameterTypes.get("stopSampling"),
1084            parameterNames.get("stopSampling"),
1085            optionals, webSocketID,
1086            "HeapProfiler.stopSampling"
1087        );
1088        
1089        // 'JSON Binding' ... Converts Browser Response-JSON to 'HeapProfiler.SamplingHeapProfile'
1090        Function<JsonObject, HeapProfiler.SamplingHeapProfile> responseProcessor = (JsonObject jo) ->
1091            ReadJSON.getObject(jo, "profile", HeapProfiler.SamplingHeapProfile.class, false, true);
1092        
1093        // Pass the 'defaultSender' to Script-Constructor
1094        // The sender that is used can be changed before executing script.
1095        return new Script<>(BRDPC.defaultSender, webSocketID, requestJSON, responseProcessor);
1096    }
1097    
1098    /**
1099     * <CODE>[No Description Provided by Google]</CODE>
1100     * 
1101     * @param reportProgress 
1102     * If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken
1103     * when the tracking is stopped.
1104     * <BR /><B>OPTIONAL</B>
1105     * 
1106     * @param treatGlobalObjectsAsRoots -
1107     * <BR /><B>OPTIONAL</B>
1108     * 
1109     * @param captureNumericValue If true, numerical values are included in the snapshot
1110     * <BR /><B>OPTIONAL</B>
1111     * 
1112     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1113     * {@link Ret0}&gt;</CODE>
1114     *
1115     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1116     * browser receives the invocation-request.
1117     *
1118     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1119     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1120     * {@code >} to ensure the Browser Function has run to completion.
1121     */
1122    public static Script<String, JsonObject, Ret0> stopTrackingHeapObjects
1123        (Boolean reportProgress, Boolean treatGlobalObjectsAsRoots, Boolean captureNumericValue)
1124    {
1125        final int       webSocketID = 3010000 + counter++;
1126        final boolean[] optionals   = { true, true, true, };
1127        
1128        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1129        String requestJSON = WriteJSON.get(
1130            parameterTypes.get("stopTrackingHeapObjects"),
1131            parameterNames.get("stopTrackingHeapObjects"),
1132            optionals, webSocketID,
1133            "HeapProfiler.stopTrackingHeapObjects",
1134            reportProgress, treatGlobalObjectsAsRoots, captureNumericValue
1135        );
1136        
1137        // This Remote Command does not have a Return-Value.
1138        return new Script<>
1139            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1140    }
1141    
1142    /**
1143     * <CODE>[No Description Provided by Google]</CODE>
1144     * 
1145     * @param reportProgress If true 'reportHeapSnapshotProgress' events will be generated while snapshot is being taken.
1146     * <BR /><B>OPTIONAL</B>
1147     * 
1148     * @param treatGlobalObjectsAsRoots If true, a raw snapshot without artificial roots will be generated
1149     * <BR /><B>OPTIONAL</B>
1150     * 
1151     * @param captureNumericValue If true, numerical values are included in the snapshot
1152     * <BR /><B>OPTIONAL</B>
1153     * 
1154     * @return An instance of <CODE>{@link Script}&lt;String, {@link JsonObject},
1155     * {@link Ret0}&gt;</CODE>
1156     *
1157     * <BR /><BR />This {@code Script} instance must be <B STYLE='color:red'>executed</B> before the
1158     * browser receives the invocation-request.
1159     *
1160     * <BR /><BR />This Browser-Function <I>does not have</I> a return-value.  You may choose to
1161     * <B STYLE='color: red'>await</B> the {@link Promise}{@code <JsonObject,} {@link Ret0}
1162     * {@code >} to ensure the Browser Function has run to completion.
1163     */
1164    public static Script<String, JsonObject, Ret0> takeHeapSnapshot
1165        (Boolean reportProgress, Boolean treatGlobalObjectsAsRoots, Boolean captureNumericValue)
1166    {
1167        final int       webSocketID = 3011000 + counter++;
1168        final boolean[] optionals   = { true, true, true, };
1169        
1170        // Convert Method Parameters into JSON.  Build the JSON Request-Object (as a String)
1171        String requestJSON = WriteJSON.get(
1172            parameterTypes.get("takeHeapSnapshot"),
1173            parameterNames.get("takeHeapSnapshot"),
1174            optionals, webSocketID,
1175            "HeapProfiler.takeHeapSnapshot",
1176            reportProgress, treatGlobalObjectsAsRoots, captureNumericValue
1177        );
1178        
1179        // This Remote Command does not have a Return-Value.
1180        return new Script<>
1181            (BRDPC.defaultSender, webSocketID, requestJSON, BRDPC.NoReturnValues);
1182    }
1183    
1184}