src/java.base/share/classes/java/lang/StackTraceElement.java
author darcy
Thu, 29 Aug 2019 16:31:34 -0700
changeset 57956 e0b8b019d2f5
parent 47866 39db80b32b69
permissions -rw-r--r--
8229997: Apply java.io.Serial annotations in java.base Reviewed-by: alanb, rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 47866
diff changeset
     2
 * Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.lang;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    28
import jdk.internal.loader.BuiltinClassLoader;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    29
import jdk.internal.misc.VM;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    30
import jdk.internal.module.ModuleHashes;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
    31
import jdk.internal.module.ModuleReferenceImpl;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    32
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    33
import java.lang.module.ModuleDescriptor.Version;
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
    34
import java.lang.module.ModuleReference;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
    35
import java.lang.module.ResolvedModule;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    36
import java.util.HashSet;
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    37
import java.util.Objects;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    38
import java.util.Optional;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    39
import java.util.Set;
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    40
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * An element in a stack trace, as returned by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Throwable#getStackTrace()}.  Each element represents a single stack frame.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * All stack frames except for the one at the top of the stack represent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * a method invocation.  The frame at the top of the stack represents the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * execution point at which the stack trace was generated.  Typically,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * this is the point at which the throwable corresponding to the stack trace
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * was created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * @since  1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * @author Josh Bloch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
public final class StackTraceElement implements java.io.Serializable {
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    54
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    55
    // For Throwables and StackWalker, the VM initially sets this field to a
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    56
    // reference to the declaring Class.  The Class reference is used to
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    57
    // construct the 'format' bitmap, and then is cleared.
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    58
    //
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    59
    // For STEs constructed using the public constructors, this field is not used.
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    60
    private transient Class<?> declaringClassObject;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    61
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    62
    // Normally initialized by VM
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    63
    private String classLoaderName;
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    64
    private String moduleName;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    65
    private String moduleVersion;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    private String declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private String methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    private String fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    private int    lineNumber;
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
    70
    private byte   format = 0; // Default to show all
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * Creates a stack trace element representing the specified execution
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    74
     * point. The {@link #getModuleName module name} and {@link
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    75
     * #getModuleVersion module version} of the stack trace element will
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    76
     * be {@code null}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * @param declaringClass the fully qualified name of the class containing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     *        the execution point represented by the stack trace element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * @param methodName the name of the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *        represented by the stack trace element
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param fileName the name of the file containing the execution point
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    83
     *         represented by the stack trace element, or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     *         this information is unavailable
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * @param lineNumber the line number of the source line containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *         execution point represented by this stack trace element, or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     *         a negative number if this information is unavailable. A value
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *         of -2 indicates that the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *         is a native method
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    90
     * @throws NullPointerException if {@code declaringClass} or
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
    91
     *         {@code methodName} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * @since 1.5
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
    93
     * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
    94
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public StackTraceElement(String declaringClass, String methodName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                             String fileName, int lineNumber) {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
    98
        this(null, null, null, declaringClass, methodName, fileName, lineNumber);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
    99
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   100
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   101
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   102
     * Creates a stack trace element representing the specified execution
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   103
     * point.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   104
     *
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   105
     * @param classLoaderName the class loader name if the class loader of
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   106
     *        the class containing the execution point represented by
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   107
     *        the stack trace is named; otherwise {@code null}
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   108
     * @param moduleName the module name if the class containing the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   109
     *        execution point represented by the stack trace is in a named
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   110
     *        module; otherwise {@code null}
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   111
     * @param moduleVersion the module version if the class containing the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   112
     *        execution point represented by the stack trace is in a named
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   113
     *        module that has a version; otherwise {@code null}
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   114
     * @param declaringClass the fully qualified name of the class containing
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   115
     *        the execution point represented by the stack trace element
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   116
     * @param methodName the name of the method containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   117
     *        represented by the stack trace element
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   118
     * @param fileName the name of the file containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   119
     *        represented by the stack trace element, or {@code null} if
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   120
     *        this information is unavailable
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   121
     * @param lineNumber the line number of the source line containing the
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   122
     *        execution point represented by this stack trace element, or
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   123
     *        a negative number if this information is unavailable. A value
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   124
     *        of -2 indicates that the method containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   125
     *        is a native method
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   126
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   127
     * @throws NullPointerException if {@code declaringClass} is {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   128
     *         or {@code methodName} is {@code null}
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   129
     *
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   130
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   131
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   132
     */
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   133
    public StackTraceElement(String classLoaderName,
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   134
                             String moduleName, String moduleVersion,
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   135
                             String declaringClass, String methodName,
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   136
                             String fileName, int lineNumber) {
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   137
        this.classLoaderName = classLoaderName;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   138
        this.moduleName      = moduleName;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   139
        this.moduleVersion   = moduleVersion;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   140
        this.declaringClass  = Objects.requireNonNull(declaringClass, "Declaring class is null");
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   141
        this.methodName      = Objects.requireNonNull(methodName, "Method name is null");
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   142
        this.fileName        = fileName;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   143
        this.lineNumber      = lineNumber;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   146
    /*
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   147
     * Private constructor for the factory methods to create StackTraceElement
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   148
     * for Throwable and StackFrameInfo
37313
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   149
     */
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   150
    private StackTraceElement() {}
37313
b0c043d9ad18 8150778: Reduce Throwable.getStackTrace() calls to the JVM
coleenp
parents: 25859
diff changeset
   151
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Returns the name of the source file containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * represented by this stack trace element.  Generally, this corresponds
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   155
     * to the {@code SourceFile} attribute of the relevant {@code class}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * file (as per <i>The Java Virtual Machine Specification</i>, Section
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * 4.7.7).  In some systems, the name may refer to some source code unit
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * other than a file, such as an entry in source repository.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @return the name of the file containing the execution point
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   161
     *         represented by this stack trace element, or {@code null} if
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *         this information is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    public String getFileName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        return fileName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * Returns the line number of the source line containing the execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * point represented by this stack trace element.  Generally, this is
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   171
     * derived from the {@code LineNumberTable} attribute of the relevant
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   172
     * {@code class} file (as per <i>The Java Virtual Machine
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Specification</i>, Section 4.7.8).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * @return the line number of the source line containing the execution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *         point represented by this stack trace element, or a negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *         number if this information is unavailable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    public int getLineNumber() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        return lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   184
     * Returns the module name of the module containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   185
     * represented by this stack trace element.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   186
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   187
     * @return the module name of the {@code Module} containing the execution
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   188
     *         point represented by this stack trace element; {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   189
     *         if the module name is not available.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   190
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   191
     * @spec JPMS
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   192
     * @see Module#getName()
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   193
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   194
    public String getModuleName() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   195
        return moduleName;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   196
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   197
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   198
    /**
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   199
     * Returns the module version of the module containing the execution point
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   200
     * represented by this stack trace element.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   201
     *
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   202
     * @return the module version of the {@code Module} containing the execution
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   203
     *         point represented by this stack trace element; {@code null}
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   204
     *         if the module version is not available.
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   205
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   206
     * @spec JPMS
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   207
     * @see java.lang.module.ModuleDescriptor.Version
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   208
     */
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   209
    public String getModuleVersion() {
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   210
        return moduleVersion;
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   211
    }
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   212
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   213
    /**
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   214
     * Returns the name of the class loader of the class containing the
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   215
     * execution point represented by this stack trace element.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   216
     *
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   217
     * @return the name of the class loader of the class containing the execution
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   218
     *         point represented by this stack trace element; {@code null}
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   219
     *         if the class loader is not named.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   220
     *
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   221
     * @since 9
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   222
     * @spec JPMS
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   223
     * @see java.lang.ClassLoader#getName()
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   224
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   225
    public String getClassLoaderName() {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   226
        return classLoaderName;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   227
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   228
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   229
    /**
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * Returns the fully qualified name of the class containing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * execution point represented by this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   233
     * @return the fully qualified name of the {@code Class} containing
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     *         the execution point represented by this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    public String getClassName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        return declaringClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Returns the name of the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     * represented by this stack trace element.  If the execution point is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * contained in an instance or class initializer, this method will return
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   244
     * the appropriate <i>special method name</i>, {@code <init>} or
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   245
     * {@code <clinit>}, as per Section 3.9 of <i>The Java Virtual
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * Machine Specification</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @return the name of the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     *         represented by this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public String getMethodName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        return methodName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Returns true if the method containing the execution point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * represented by this stack trace element is a native method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   259
     * @return {@code true} if the method containing the execution point
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *         represented by this stack trace element is a native method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    public boolean isNativeMethod() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return lineNumber == -2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   267
     * Returns a string representation of this stack trace element.
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   268
     *
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   269
     * @apiNote The format of this string depends on the implementation, but the
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   270
     * following examples may be regarded as typical:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * <li>
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   273
     *     "{@code com.foo.loader/foo@9.0/com.foo.Main.run(Main.java:101)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   274
     * - See the description below.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   275
     * </li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   276
     * <li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   277
     *     "{@code com.foo.loader/foo@9.0/com.foo.Main.run(Main.java)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   278
     * - The line number is unavailable.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   279
     * </li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   280
     * <li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   281
     *     "{@code com.foo.loader/foo@9.0/com.foo.Main.run(Unknown Source)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   282
     * - Neither the file name nor the line number is available.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   283
     * </li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   284
     * <li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   285
     *     "{@code com.foo.loader/foo@9.0/com.foo.Main.run(Native Method)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   286
     * - The method containing the execution point is a native method.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   287
     * </li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   288
     * <li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   289
     *     "{@code com.foo.loader//com.foo.bar.App.run(App.java:12)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   290
     * - The class of the execution point is defined in the unnamed module of
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   291
     * the class loader named {@code com.foo.loader}.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   292
     * </li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   293
     * <li>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   294
     *     "{@code acme@2.1/org.acme.Lib.test(Lib.java:80)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   295
     * - The class of the execution point is defined in {@code acme} module
47866
39db80b32b69 8191632: Typos in comments due to duplicating words
igerasim
parents: 47216
diff changeset
   296
     * loaded by a built-in class loader such as the application class loader.
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   297
     * </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * <li>
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   299
     *     "{@code MyClass.mash(MyClass.java:9)}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   300
     * - {@code MyClass} class is on the application class path.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   301
     * </li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * </ul>
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   303
     *
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   304
     * <p> The first example shows a stack trace element consisting of
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   305
     * three elements, each separated by {@code "/"} followed with
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   306
     * the source file name and the line number of the source line
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   307
     * containing the execution point.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   308
     *
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   309
     * The first element "{@code com.foo.loader}" is
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   310
     * the name of the class loader.  The second element "{@code foo@9.0}"
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   311
     * is the module name and version.  The third element is the method
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   312
     * containing the execution point; "{@code com.foo.Main"}" is the
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   313
     * fully-qualified class name and "{@code run}" is the name of the method.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   314
     * "{@code Main.java}" is the source file name and "{@code 101}" is
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   315
     * the line number.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   316
     *
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   317
     * <p> If a class is defined in an <em>unnamed module</em>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   318
     * then the second element is omitted as shown in
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   319
     * "{@code com.foo.loader//com.foo.bar.App.run(App.java:12)}".
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   320
     *
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   321
     * <p> If the class loader is a <a href="ClassLoader.html#builtinLoaders">
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   322
     * built-in class loader</a> or is not named then the first element
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   323
     * and its following {@code "/"} are omitted as shown in
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   324
     * "{@code acme@2.1/org.acme.Lib.test(Lib.java:80)}".
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   325
     * If the first element is omitted and the module is an unnamed module,
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   326
     * the second element and its following {@code "/"} are also omitted
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   327
     * as shown in "{@code MyClass.mash(MyClass.java:9)}".
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   328
     *
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   329
     * <p> The {@code toString} method may return two different values on two
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   330
     * {@code StackTraceElement} instances that are
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   331
     * {@linkplain #equals(Object) equal}, for example one created via the
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   332
     * constructor, and one obtained from {@link java.lang.Throwable} or
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   333
     * {@link java.lang.StackWalker.StackFrame}, where an implementation may
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   334
     * choose to omit some element in the returned string.
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   335
     *
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   336
     * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   337
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @see    Throwable#printStackTrace()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public String toString() {
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   341
        String s = "";
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   342
        if (!dropClassLoaderName() && classLoaderName != null &&
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   343
                !classLoaderName.isEmpty()) {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   344
            s += classLoaderName + "/";
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   345
        }
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   346
        if (moduleName != null && !moduleName.isEmpty()) {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   347
            s += moduleName;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   348
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   349
            if (!dropModuleVersion() && moduleVersion != null &&
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   350
                    !moduleVersion.isEmpty()) {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   351
                s += "@" + moduleVersion;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   352
            }
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   353
        }
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   354
        s = s.isEmpty() ? declaringClass : s + "/" + declaringClass;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   355
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   356
        return s + "." + methodName + "(" +
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   357
             (isNativeMethod() ? "Native Method)" :
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   358
              (fileName != null && lineNumber >= 0 ?
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   359
               fileName + ":" + lineNumber + ")" :
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   360
                (fileName != null ?  ""+fileName+")" : "Unknown Source)")));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * Returns true if the specified object is another
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   365
     * {@code StackTraceElement} instance representing the same execution
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   366
     * point as this instance.  Two stack trace elements {@code a} and
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   367
     * {@code b} are equal if and only if:
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9035
diff changeset
   368
     * <pre>{@code
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   369
     *     equals(a.getClassLoaderName(), b.getClassLoaderName()) &&
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   370
     *     equals(a.getModuleName(), b.getModuleName()) &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   371
     *     equals(a.getModuleVersion(), b.getModuleVersion()) &&
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *     equals(a.getClassName(), b.getClassName()) &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     *     equals(a.getMethodName(), b.getMethodName())
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   374
     *     equals(a.getFileName(), b.getFileName()) &&
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   375
     *     a.getLineNumber() == b.getLineNumber()
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   376
     *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9035
diff changeset
   377
     * }</pre>
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   378
     * where {@code equals} has the semantics of {@link
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   379
     * java.util.Objects#equals(Object, Object) Objects.equals}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * @param  obj the object to be compared with this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * @return true if the specified object is another
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   383
     *         {@code StackTraceElement} instance representing the same
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *         execution point as this instance.
43712
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   385
     *
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   386
     * @revised 9
5dfd0950317c 8173393: Module system implementation refresh (2/2017)
alanb
parents: 42704
diff changeset
   387
     * @spec JPMS
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
        if (obj==this)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        if (!(obj instanceof StackTraceElement))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        StackTraceElement e = (StackTraceElement)obj;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   395
        return Objects.equals(classLoaderName, e.classLoaderName) &&
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   396
            Objects.equals(moduleName, e.moduleName) &&
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   397
            Objects.equals(moduleVersion, e.moduleVersion) &&
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   398
            e.declaringClass.equals(declaringClass) &&
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   399
            e.lineNumber == lineNumber &&
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   400
            Objects.equals(methodName, e.methodName) &&
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   401
            Objects.equals(fileName, e.fileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Returns a hash code value for this stack trace element.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        int result = 31*declaringClass.hashCode() + methodName.hashCode();
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   409
        result = 31*result + Objects.hashCode(classLoaderName);
36511
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   410
        result = 31*result + Objects.hashCode(moduleName);
9d0388c6b336 8142968: Module System implementation
alanb
parents: 25859
diff changeset
   411
        result = 31*result + Objects.hashCode(moduleVersion);
7186
7f5fe8985263 6991528: Support making Throwable.suppressedExceptions immutable
darcy
parents: 5506
diff changeset
   412
        result = 31*result + Objects.hashCode(fileName);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
        result = 31*result + lineNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   417
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   418
    /**
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   419
     * Called from of() methods to set the 'format' bitmap using the Class
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   420
     * reference stored in declaringClassObject, and then clear the reference.
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   421
     *
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   422
     * <p>
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   423
     * If the module is a non-upgradeable JDK module, then set
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   424
     * JDK_NON_UPGRADEABLE_MODULE to omit its version string.
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   425
     * <p>
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   426
     * If the loader is one of the built-in loaders (`boot`, `platform`, or `app`)
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   427
     * then set BUILTIN_CLASS_LOADER to omit the first element (`<loader>/`).
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   428
     */
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   429
    private synchronized void computeFormat() {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   430
        try {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   431
            Class<?> cls = (Class<?>) declaringClassObject;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   432
            ClassLoader loader = cls.getClassLoader0();
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   433
            Module m = cls.getModule();
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   434
            byte bits = 0;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   435
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   436
            // First element - class loader name
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   437
            // Call package-private ClassLoader::name method
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   438
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   439
            if (loader instanceof BuiltinClassLoader) {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   440
                bits |= BUILTIN_CLASS_LOADER;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   441
            }
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   442
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   443
            // Second element - module name and version
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   444
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   445
            // Omit if is a JDK non-upgradeable module (recorded in the hashes
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   446
            // in java.base)
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   447
            if (isHashedInJavaBase(m)) {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   448
                bits |= JDK_NON_UPGRADEABLE_MODULE;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   449
            }
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   450
            format = bits;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   451
        } finally {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   452
            // Class reference no longer needed, clear it
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   453
            declaringClassObject = null;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   454
        }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   455
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   456
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   457
    private static final byte BUILTIN_CLASS_LOADER       = 0x1;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   458
    private static final byte JDK_NON_UPGRADEABLE_MODULE = 0x2;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   459
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   460
    private boolean dropClassLoaderName() {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   461
        return (format & BUILTIN_CLASS_LOADER) == BUILTIN_CLASS_LOADER;
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   462
    }
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   463
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   464
    private boolean dropModuleVersion() {
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   465
        return (format & JDK_NON_UPGRADEABLE_MODULE) == JDK_NON_UPGRADEABLE_MODULE;
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   466
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   467
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   468
    /**
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   469
     * Returns true if the module is hashed with java.base.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   470
     * <p>
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   471
     * This method returns false when running on the exploded image
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   472
     * since JDK modules are not hashed. They have no Version attribute
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   473
     * and so "@<version>" part will be omitted anyway.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   474
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   475
    private static boolean isHashedInJavaBase(Module m) {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   476
        // return true if module system is not initialized as the code
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   477
        // must be in java.base
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   478
        if (!VM.isModuleSystemInited())
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   479
            return true;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   480
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   481
        return ModuleLayer.boot() == m.getLayer() && HashedModules.contains(m);
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   482
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   483
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   484
    /*
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   485
     * Finds JDK non-upgradeable modules, i.e. the modules that are
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   486
     * included in the hashes in java.base.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   487
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   488
    private static class HashedModules {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   489
        static Set<String> HASHED_MODULES = hashedModules();
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   490
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   491
        static Set<String> hashedModules() {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   492
44545
83b611b88ac8 8177530: Module system implementation refresh (4/2017)
alanb
parents: 43712
diff changeset
   493
            Optional<ResolvedModule> resolvedModule = ModuleLayer.boot()
42703
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   494
                    .configuration()
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   495
                    .findModule("java.base");
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   496
            assert resolvedModule.isPresent();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   497
            ModuleReference mref = resolvedModule.get().reference();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   498
            assert mref instanceof ModuleReferenceImpl;
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   499
            ModuleHashes hashes = ((ModuleReferenceImpl)mref).recordedHashes();
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   500
            if (hashes != null) {
20c39ea4a507 8170987: Module system implementation refresh (12/2016)
alanb
parents: 41911
diff changeset
   501
                Set<String> names = new HashSet<>(hashes.names());
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   502
                names.add("java.base");
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   503
                return names;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   504
            }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   505
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   506
            return Set.of();
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   507
        }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   508
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   509
        static boolean contains(Module m) {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   510
            return HASHED_MODULES.contains(m.getName());
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   511
        }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   512
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   513
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   514
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   515
    /*
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   516
     * Returns an array of StackTraceElements of the given depth
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   517
     * filled from the backtrace of a given Throwable.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   518
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   519
    static StackTraceElement[] of(Throwable x, int depth) {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   520
        StackTraceElement[] stackTrace = new StackTraceElement[depth];
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   521
        for (int i = 0; i < depth; i++) {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   522
            stackTrace[i] = new StackTraceElement();
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   523
        }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   524
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   525
        // VM to fill in StackTraceElement
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   526
        initStackTraceElements(stackTrace, x);
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   527
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   528
        // ensure the proper StackTraceElement initialization
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   529
        for (StackTraceElement ste : stackTrace) {
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   530
            ste.computeFormat();
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   531
        }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   532
        return stackTrace;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   533
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   534
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   535
    /*
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   536
     * Returns a StackTraceElement from a given StackFrameInfo.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   537
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   538
    static StackTraceElement of(StackFrameInfo sfi) {
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   539
        StackTraceElement ste = new StackTraceElement();
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   540
        initStackTraceElement(ste, sfi);
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   541
42672
92a8c56354ab 8169389: Use a bitmap to control StackTraceElement::toString format and save footprint
bchristi
parents: 41911
diff changeset
   542
        ste.computeFormat();
41911
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   543
        return ste;
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   544
    }
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   545
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   546
    /*
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   547
     * Sets the given stack trace elements with the backtrace
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   548
     * of the given Throwable.
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   549
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   550
    private static native void initStackTraceElements(StackTraceElement[] elements,
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   551
                                                      Throwable x);
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   552
    /*
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   553
     * Sets the given stack trace element with the given StackFrameInfo
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   554
     */
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   555
    private static native void initStackTraceElement(StackTraceElement element,
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   556
                                                     StackFrameInfo sfi);
b3bb62588635 6479237: (cl) Add support for classloader names
mchung
parents: 37325
diff changeset
   557
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 47866
diff changeset
   558
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    private static final long serialVersionUID = 6992337162326171013L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
}