/* * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
privatestaticfinal Unsafe U = Unsafe.getUnsafe(); privatestaticint ADDRESS_SIZE; privatestaticint HEADER_SIZE;
static { // When running with CompressedOops on 64-bit platform, the address size // reported by Unsafe is still 8, while the real reference fields are 4 bytes long. // Try to guess the reference field size with this naive trick. try { long off1 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj1")); long off2 = U.objectFieldOffset(CompressedOopsClass.class.getField("obj2"));
ADDRESS_SIZE = (int) Math.abs(off2 - off1);
HEADER_SIZE = (int) Math.min(off1, off2);
} catch (NoSuchFieldException e) {
ADDRESS_SIZE = -1;
}
}
staticclass CompressedOopsClass { public Object obj1; public Object obj2;
}
publicstaticboolean arePaddedPairwise(Class klass, String field1, String field2) throwsException {
Field f1 = klass.getDeclaredField(field1);
Field f2 = klass.getDeclaredField(field2);
if (isStatic(f1) != isStatic(f2)) { returntrue; // these guys are in naturally disjoint locations
}
int diff = offset(f1) - offset(f2); if (diff < 0) { // f1 is first return (offset(f2) - (offset(f1) + getSize(f1))) > 64;
} else { // f2 is first return (offset(f1) - (offset(f2) + getSize(f2))) > 64;
}
}
publicstaticboolean isPadded(Class klass, String field1) throws Exception {
Field f1 = klass.getDeclaredField(field1);
if (isStatic(f1)) { return offset(f1) > 128 + 64;
}
return offset(f1) > 64;
}
publicstaticboolean sameLayout(Class klass1, Class klass2) throws Exception { for (Field f1 : klass1.getDeclaredFields()) {
Field f2 = klass2.getDeclaredField(f1.getName()); if (offset(f1) != offset(f2)) { returnfalse;
}
}
for (Field f2 : klass1.getDeclaredFields()) {
Field f1 = klass2.getDeclaredField(f2.getName()); if (offset(f1) != offset(f2)) { returnfalse;
}
}
// both fields are padded publicstaticclass Test3 {
@Contended privateint int1;
@Contended privateint int2;
}
// fields are padded in the singular group publicstaticclass Test4 {
@Contended("sameGroup") privateint int1;
@Contended("sameGroup") privateint int2;
}
// fields are padded in disjoint groups publicstaticclass Test5 {
@Contended("diffGroup1") privateint int1;
@Contended("diffGroup2") privateint int2;
}
// fields are padded in disjoint groups publicstaticclass Test6 {
@Contended privateint int1;
@Contended("diffGroup2") privateint int2;
}
// fields are padded in the singular group
@Contended publicstaticclass Test7 { privateint int1; privateint int2;
}
// all fields are padded as the group, and one field is padded specifically
@Contended publicstaticclass Test8 {
@Contended privateint int1; privateint int2;
}
// all fields are padded as the group, and one field is padded specifically
@Contended publicstaticclass Test9 {
@Contended("group") privateint int1; privateint int2;
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.