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