Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove serialization. #727

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" ?>

<FindBugsFilter>
<!-- In general, do not run this on tests or generated benchmark classes -->
<Match>
<!-- In general, do not run this on tests or generated benchmark classes -->
<Source name="~.*\/testsrc\/.*"/>
</Match>
<Match>
Expand Down Expand Up @@ -103,21 +103,22 @@
<Class name="org.mozilla.javascript.optimizer.OptRuntime$GeneratorState"/>
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD"/>
</Match>
<!-- Complex legacy stuff -->
<!--<Match>
<Class name="org.mozilla.javascript.regexp.RegExpImpl"/>
<Bug pattern="RC_REF_COMPARISON_BAD_PRACTICE_BOOLEAN"/>
</Match>-->

<!-- Things below are things that we aspire to fix! -->
<Match>
<!-- We are planning to eliminate serialization -->
<!-- We are generally not making things serializable, so not comparators -->
<Bug pattern="SE_COMPARATOR_SHOULD_BE_SERIALIZABLE"/>
</Match>
<Match>
<!-- We aren't going to be serializing these inherited things -->
<Class name="org.mozilla.javascript.tools.shell.JavaPolicySecurity$ContextPermissions"/>
<Bug pattern="SE_BAD_FIELD"/>
</Match>
<Match>
<!-- We are planning to eliminate serialization -->
<Bug pattern="SE_TRANSIENT_FIELD_NOT_RESTORED"/>
<!-- We aren't going to be serializing these inherited things -->
<Class name="org.mozilla.javascript.tools.shell.Main$ScriptCache"/>
<Bug pattern="SE_BAD_FIELD"/>
</Match>

<!-- Things below are things that we aspire to fix! -->
<Match>
<!-- We are planning to get rid of synchronization -->
<Bug pattern="DC_DOUBLECHECK"/>
Expand Down
4 changes: 1 addition & 3 deletions src/org/mozilla/javascript/ClassCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package org.mozilla.javascript;

import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

Expand All @@ -18,9 +17,8 @@
*
* @since Rhino 1.5 Release 5
*/
public class ClassCache implements Serializable
public class ClassCache
{
private static final long serialVersionUID = -8866246036237312215L;
private static final Object AKEY = "ClassCache";
private volatile boolean cachingIsEnabled = true;
private transient Map<Class<?>,JavaMembers> classTable;
Expand Down
3 changes: 0 additions & 3 deletions src/org/mozilla/javascript/CodeGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.mozilla.javascript.ast.Jump;
import org.mozilla.javascript.ast.Scope;
import org.mozilla.javascript.ast.ScriptNode;
import org.mozilla.javascript.ast.VariableInitializer;

/**
* Generates bytecode for the Interpreter.
Expand Down Expand Up @@ -112,8 +111,6 @@ private void generateFunctionICode()
itsData.isES6Generator = true;
}

itsData.declaredAsVar = (theFunction.getParent() instanceof VariableInitializer);

generateICodeFromTree(theFunction.getLastChild());
}

Expand Down
10 changes: 1 addition & 9 deletions src/org/mozilla/javascript/ConsString.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package org.mozilla.javascript;

import java.io.Serializable;
import java.util.ArrayDeque;

/**
Expand All @@ -25,9 +24,7 @@
*
* <p>Both the name and the concept are borrowed from V8.</p>
*/
public class ConsString implements CharSequence, Serializable {

private static final long serialVersionUID = -8432806714471372570L;
public class ConsString implements CharSequence {

private CharSequence left, right;
private final int length;
Expand All @@ -39,11 +36,6 @@ public ConsString(CharSequence str1, CharSequence str2) {
length = left.length() + right.length();
isFlat = false;
}

// Replace with string representation when serializing
private Object writeReplace() {
return this.toString();
}

@Override
public String toString() {
Expand Down
7 changes: 2 additions & 5 deletions src/org/mozilla/javascript/Hashtable.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mozilla.javascript;

import java.io.Serializable;
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
Expand All @@ -26,9 +25,8 @@
* exist, and even lets an iterator keep on iterating on a collection that was
* empty when it was created..
*/
public class Hashtable implements Serializable, Iterable<Hashtable.Entry> {
public class Hashtable implements Iterable<Hashtable.Entry> {

private static final long serialVersionUID = -7151554912419543747L;
private final HashMap<Object, Entry> map = new HashMap<>();
private Entry first = null;
private Entry last = null;
Expand All @@ -39,8 +37,7 @@ public class Hashtable implements Serializable, Iterable<Hashtable.Entry> {
* node in the linked list.
*/

public static final class Entry implements Serializable {
private static final long serialVersionUID = 4086572107122965503L;
public static final class Entry {
protected Object key;
protected Object value;
protected boolean deleted;
Expand Down
32 changes: 1 addition & 31 deletions src/org/mozilla/javascript/IdScriptableObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

package org.mozilla.javascript;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
* Base class for native object implementation that uses IdFunctionObject to
* export its methods to script via &lt;class-name&gt;.prototype object.
Expand All @@ -28,12 +23,9 @@
*
*/
public abstract class IdScriptableObject extends ScriptableObject implements IdFunctionCall {
private static final long serialVersionUID = -3744239272168621609L;
private transient PrototypeValues prototypeValues;

private static final class PrototypeValues implements Serializable {
private static final long serialVersionUID = 3038645279153854371L;

private static final class PrototypeValues {
private static final int NAME_SLOT = 1;
private static final int SLOT_SPAN = 2;

Expand Down Expand Up @@ -1039,27 +1031,5 @@ private ScriptableObject getBuiltInDescriptor(Symbol key) {
}
return null;
}

private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException
{
stream.defaultReadObject();
int maxPrototypeId = stream.readInt();
if (maxPrototypeId != 0) {
activatePrototypeMap(maxPrototypeId);
}
}

private void writeObject(ObjectOutputStream stream)
throws IOException
{
stream.defaultWriteObject();
int maxPrototypeId = 0;
if (prototypeValues != null) {
maxPrototypeId = prototypeValues.getMaxId();
}
stream.writeInt(maxPrototypeId);
}

}

9 changes: 2 additions & 7 deletions src/org/mozilla/javascript/Interpreter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import static org.mozilla.javascript.UniqueTag.DOUBLE_MARK;

import java.io.PrintStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -38,10 +37,8 @@ public final class Interpreter extends Icode implements Evaluator
/**
* Class to hold data corresponding to one interpreted call stack frame.
*/
private static class CallFrame implements Cloneable, Serializable
private static class CallFrame implements Cloneable
{
private static final long serialVersionUID = -2843792508994958978L;

// fields marked "final" in a comment are effectively final except when they're modified immediately after cloning.

/*final*/ CallFrame parentFrame;
Expand Down Expand Up @@ -293,10 +290,8 @@ private static boolean compareIdata(InterpreterData i1, InterpreterData i2) {
return i1 == i2 || Objects.equals(getEncodedSource(i1), getEncodedSource(i2));
}

private static final class ContinuationJump implements Serializable
private static final class ContinuationJump
{
private static final long serialVersionUID = 7687739156004308247L;

CallFrame capturedFrame;
CallFrame branchFrame;
Object result;
Expand Down
8 changes: 1 addition & 7 deletions src/org/mozilla/javascript/InterpreterData.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

package org.mozilla.javascript;

import java.io.Serializable;
import java.util.Arrays;

import org.mozilla.javascript.debug.DebuggableScript;

final class InterpreterData implements Serializable, DebuggableScript
final class InterpreterData implements DebuggableScript
{
private static final long serialVersionUID = 5067677351589230234L;

static final int INITIAL_MAX_ICODE_LENGTH = 1024;
static final int INITIAL_STRINGTABLE_SIZE = 64;
static final int INITIAL_NUMBERTABLE_SIZE = 64;
Expand Down Expand Up @@ -93,9 +90,6 @@ private void init()

private int icodeHashCode = 0;

/** true if the function has been declared like "var foo = function() {...}" */
boolean declaredAsVar;

/** true if the function has been declared like "!function() {}". */
boolean declaredAsFunctionExpression;

Expand Down
4 changes: 1 addition & 3 deletions src/org/mozilla/javascript/LazilyLoadedCtor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

package org.mozilla.javascript;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
Expand All @@ -16,8 +15,7 @@
*
* <p> This improves startup time and average memory usage.
*/
public final class LazilyLoadedCtor implements Serializable {
private static final long serialVersionUID = 1L;
public final class LazilyLoadedCtor {
private static final int STATE_BEFORE_INIT = 0;
private static final int STATE_INITIALIZING = 1;
private static final int STATE_WITH_VALUE = 2;
Expand Down
Loading