提交 f1f305f0 编写于 作者: V vromero

8005075: Pool.Method, and Pool.Variable redundant Symbol field should be removed

Reviewed-by: jjg
上级 29e2e162
...@@ -496,9 +496,9 @@ public abstract class Symbol implements Element { ...@@ -496,9 +496,9 @@ public abstract class Symbol implements Element {
return l.toList(); return l.toList();
} }
public static class DelegatedSymbol extends Symbol { public static class DelegatedSymbol<T extends Symbol> extends Symbol {
protected Symbol other; protected T other;
public DelegatedSymbol(Symbol other) { public DelegatedSymbol(T other) {
super(other.kind, other.flags_field, other.name, other.type, other.owner); super(other.kind, other.flags_field, other.name, other.type, other.owner);
this.other = other; this.other = other;
} }
...@@ -532,6 +532,10 @@ public abstract class Symbol implements Element { ...@@ -532,6 +532,10 @@ public abstract class Symbol implements Element {
public <R, P> R accept(Symbol.Visitor<R, P> v, P p) { public <R, P> R accept(Symbol.Visitor<R, P> v, P p) {
return v.visitSymbol(other, p); return v.visitSymbol(other, p);
} }
public T getUnderlyingSymbol() {
return other;
}
} }
/** A class for type symbols. Type variables are represented by instances /** A class for type symbols. Type variables are represented by instances
......
...@@ -482,10 +482,8 @@ public class ClassWriter extends ClassFile { ...@@ -482,10 +482,8 @@ public class ClassWriter extends ClassFile {
while (i < pool.pp) { while (i < pool.pp) {
Object value = pool.pool[i]; Object value = pool.pool[i];
Assert.checkNonNull(value); Assert.checkNonNull(value);
if (value instanceof Method) if (value instanceof Method || value instanceof Variable)
value = ((Method)value).m; value = ((DelegatedSymbol)value).getUnderlyingSymbol();
else if (value instanceof Variable)
value = ((Variable)value).v;
if (value instanceof MethodSymbol) { if (value instanceof MethodSymbol) {
MethodSymbol m = (MethodSymbol)value; MethodSymbol m = (MethodSymbol)value;
......
/* /*
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
...@@ -140,23 +140,23 @@ public class Pool { ...@@ -140,23 +140,23 @@ public class Pool {
return n == null ? -1 : n.intValue(); return n == null ? -1 : n.intValue();
} }
static class Method extends DelegatedSymbol { static class Method extends DelegatedSymbol<MethodSymbol> {
MethodSymbol m;
UniqueType uniqueType; UniqueType uniqueType;
Method(MethodSymbol m, Types types) { Method(MethodSymbol m, Types types) {
super(m); super(m);
this.m = m;
this.uniqueType = new UniqueType(m.type, types); this.uniqueType = new UniqueType(m.type, types);
} }
public boolean equals(Object other) { public boolean equals(Object any) {
if (!(other instanceof Method)) return false; if (!(any instanceof Method)) return false;
MethodSymbol o = ((Method)other).m; MethodSymbol o = ((Method)any).other;
MethodSymbol m = this.other;
return return
o.name == m.name && o.name == m.name &&
o.owner == m.owner && o.owner == m.owner &&
((Method)other).uniqueType.equals(uniqueType); ((Method)any).uniqueType.equals(uniqueType);
} }
public int hashCode() { public int hashCode() {
MethodSymbol m = this.other;
return return
m.name.hashCode() * 33 + m.name.hashCode() * 33 +
m.owner.hashCode() * 9 + m.owner.hashCode() * 9 +
...@@ -173,21 +173,21 @@ public class Pool { ...@@ -173,21 +173,21 @@ public class Pool {
} }
@Override @Override
public boolean equals(Object other) { public boolean equals(Object any) {
if (!super.equals(other)) return false; if (!super.equals(any)) return false;
if (!(other instanceof DynamicMethod)) return false; if (!(any instanceof DynamicMethod)) return false;
DynamicMethodSymbol dm1 = (DynamicMethodSymbol)m; DynamicMethodSymbol dm1 = (DynamicMethodSymbol)other;
DynamicMethodSymbol dm2 = (DynamicMethodSymbol)((DynamicMethod)other).m; DynamicMethodSymbol dm2 = (DynamicMethodSymbol)((DynamicMethod)any).other;
return dm1.bsm == dm2.bsm && return dm1.bsm == dm2.bsm &&
dm1.bsmKind == dm2.bsmKind && dm1.bsmKind == dm2.bsmKind &&
Arrays.equals(uniqueStaticArgs, Arrays.equals(uniqueStaticArgs,
((DynamicMethod)other).uniqueStaticArgs); ((DynamicMethod)any).uniqueStaticArgs);
} }
@Override @Override
public int hashCode() { public int hashCode() {
int hash = super.hashCode(); int hash = super.hashCode();
DynamicMethodSymbol dm = (DynamicMethodSymbol)m; DynamicMethodSymbol dm = (DynamicMethodSymbol)other;
hash += dm.bsmKind * 7 + hash += dm.bsmKind * 7 +
dm.bsm.hashCode() * 11; dm.bsm.hashCode() * 11;
for (int i = 0; i < dm.staticArgs.length; i++) { for (int i = 0; i < dm.staticArgs.length; i++) {
...@@ -209,23 +209,23 @@ public class Pool { ...@@ -209,23 +209,23 @@ public class Pool {
} }
} }
static class Variable extends DelegatedSymbol { static class Variable extends DelegatedSymbol<VarSymbol> {
VarSymbol v;
UniqueType uniqueType; UniqueType uniqueType;
Variable(VarSymbol v, Types types) { Variable(VarSymbol v, Types types) {
super(v); super(v);
this.v = v;
this.uniqueType = new UniqueType(v.type, types); this.uniqueType = new UniqueType(v.type, types);
} }
public boolean equals(Object other) { public boolean equals(Object any) {
if (!(other instanceof Variable)) return false; if (!(any instanceof Variable)) return false;
VarSymbol o = ((Variable)other).v; VarSymbol o = ((Variable)any).other;
VarSymbol v = other;
return return
o.name == v.name && o.name == v.name &&
o.owner == v.owner && o.owner == v.owner &&
((Variable)other).uniqueType.equals(uniqueType); ((Variable)any).uniqueType.equals(uniqueType);
} }
public int hashCode() { public int hashCode() {
VarSymbol v = other;
return return
v.name.hashCode() * 33 + v.name.hashCode() * 33 +
v.owner.hashCode() * 9 + v.owner.hashCode() * 9 +
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册