mirror of
https://github.com/corda/corda.git
synced 2025-01-08 14:03:06 +00:00
866c057f0d
getDeclaredMethods was returning methods which were inherited from interfaces but not (re)declared in the class itself, due to the VM's internal use of VMClass.methodTable differing from its role in reflection. For reflection, we must only include the declared methods, not the inherited but un-redeclared ones. Previously, we saved the original method table in ClassAddendum.methodTable before creating a new one which contains both declared and inherited methods. That wasted space, so this patch replaces ClassAddendum.methodTable with ClassAddendum.declaredMethodCount, which specifies how many of the methods in VMClass.methodTable were declared in that class. Alternatively, we could ensure that undeclared methods always have their VMMethod.class_ field set to the declaring class instead of the inheriting class. I tried this, but it led to subtle crashes in interface method lookup. The rest of the VM relies not only on VMClass.methodTable containing all inherited interface methods but also that those methods point to the inheriting class, not the declaring class. Changing those assumptions would be a much bigger (and more dangerous in terms of regression potential) effort than I care to take on right now. The solution I chose is a bit ugly, but it's safe.
42 lines
1.3 KiB
Java
42 lines
1.3 KiB
Java
/* Copyright (c) 2008-2013, Avian Contributors
|
|
|
|
Permission to use, copy, modify, and/or distribute this software
|
|
for any purpose with or without fee is hereby granted, provided
|
|
that the above copyright notice and this permission notice appear
|
|
in all copies.
|
|
|
|
There is NO WARRANTY for this software. See license.txt for
|
|
details. */
|
|
|
|
package avian;
|
|
|
|
public class VMClass {
|
|
public short flags;
|
|
public short vmFlags;
|
|
public short fixedSize;
|
|
public byte arrayElementSize;
|
|
public byte arrayDimensions;
|
|
public int runtimeDataIndex;
|
|
public int[] objectMask;
|
|
public byte[] name;
|
|
public byte[] sourceFile;
|
|
public VMClass super_;
|
|
public Object[] interfaceTable;
|
|
public VMMethod[] virtualTable;
|
|
public VMField[] fieldTable;
|
|
/**
|
|
* Methods declared in this class, plus any abstract virtual methods
|
|
* inherited from implemented or extended interfaces. If addendum
|
|
* is non-null and addendum.declaredMethodCount is non-negative,
|
|
* then the first addendum.declaredMethodCount methods are declared
|
|
* methods, while the rest are abstract virtual methods. If
|
|
* addendum is null or addendum.declaredMethodCount is negative, all
|
|
* are declared methods.
|
|
*/
|
|
public VMMethod[] methodTable;
|
|
public ClassAddendum addendum;
|
|
public Object staticTable;
|
|
public ClassLoader loader;
|
|
public byte[] source;
|
|
}
|