1 /*
2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * This code is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License version 2 only, as
7  * published by the Free Software Foundation.  Oracle designates this
8  * particular file as subject to the "Classpath" exception as provided
9  * by Oracle in the LICENSE file that accompanied this code.
10  *
11  * This code is distributed in the hope that it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14  * version 2 for more details (a copy is included in the LICENSE file that
15  * accompanied this code).
16  *
17  * You should have received a copy of the GNU General Public License version
18  * 2 along with this work; if not, write to the Free Software Foundation,
19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20  *
21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22  * or visit www.oracle.com if you need additional information or have any
23  * questions.
24  */
25 
26 package jdk.nashorn.internal.runtime.events;
27 
28 import java.util.logging.Level;
29 import jdk.nashorn.internal.runtime.Context;
30 import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData;
31 import jdk.nashorn.internal.runtime.RewriteException;
32 
33 /**
34  * Subclass of runtime event for {@link RewriteException}. In order not
35  * to leak memory, RewriteExceptions get their return value destroyed
36  * and nulled out during recompilation. If we are running with event
37  * logging enabled, we need to retain the returnValue, hence the extra
38  * field
39  */
40 public final class RecompilationEvent extends RuntimeEvent<RewriteException> {
41 
42     private final Object returnValue;
43 
44     /**
45      * Constructor
46      *
47      * @param level            logging level
48      * @param rewriteException rewriteException wrapped by this RuntimEvent
49      * @param returnValue      rewriteException return value - as we don't want to make
50      *     {@code RewriteException.getReturnValueNonDestructive()} public, we pass it as
51      *     an extra parameter, rather than querying the getter from another package.
52      */
RecompilationEvent(final Level level, final RewriteException rewriteException, final Object returnValue)53     public RecompilationEvent(final Level level, final RewriteException rewriteException, final Object returnValue) {
54         super(level, rewriteException);
55         assert Context.getContext().getLogger(RecompilableScriptFunctionData.class).isEnabled() :
56             "Unit test/instrumentation purpose only: RecompilationEvent instances should not be created without '--log=recompile', or we will leak memory in the general case";
57         this.returnValue = returnValue;
58     }
59 
60     /**
61      * Get the preserved return value for the RewriteException
62      * @return return value
63      */
getReturnValue()64     public Object getReturnValue() {
65         return returnValue;
66     }
67 }
68