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