src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/AstDeserializer.java
author hannesw
Wed, 21 Mar 2018 16:55:34 +0100
changeset 49275 c639a6b33c5c
parent 47216 71c04702a3d5
permissions -rw-r--r--
8199869: Missing copyright headers in nashorn source code Reviewed-by: sundar
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     1
/*
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     2
 * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     4
 *
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    10
 *
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    15
 * accompanied this code).
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    16
 *
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    20
 *
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    23
 * questions.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    24
 */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    25
package jdk.nashorn.internal.runtime;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    26
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    27
import java.io.ByteArrayInputStream;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    28
import java.io.IOException;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    29
import java.io.ObjectInputStream;
27825
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    30
import java.security.AccessController;
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    31
import java.security.PrivilegedAction;
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    32
import java.util.zip.InflaterInputStream;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    33
import jdk.nashorn.internal.ir.FunctionNode;
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    34
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    35
/**
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    36
 * This static utility class performs deserialization of FunctionNode ASTs from a byte array.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    37
 * The format is a standard Java serialization stream, deflated.
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    38
 */
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    39
final class AstDeserializer {
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    40
    static FunctionNode deserialize(final byte[] serializedAst) {
27825
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    41
        return AccessController.doPrivileged(new PrivilegedAction<FunctionNode>() {
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    42
            @Override
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    43
            public FunctionNode run() {
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    44
                try {
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    45
                    return (FunctionNode)new ObjectInputStream(new InflaterInputStream(
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    46
                        new ByteArrayInputStream(serializedAst))).readObject();
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    47
                } catch (final ClassNotFoundException | IOException e) {
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    48
                    // This is internal, can't happen
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    49
                    throw new AssertionError("Unexpected exception deserializing function", e);
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    50
                }
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    51
            }
cbb30ab946ee 8066683: nashorn test failures after modular image changes
sundar
parents: 27206
diff changeset
    52
        });
27206
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    53
    }
d4a707c9db5a 8059844: Implement optimistic splitter
attila
parents:
diff changeset
    54
}