Check-in [352c832c8e]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Sort fields to group them together better.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:352c832c8e40ea4a5af03fd14be593ceffb98397
User & Date: stephanie.gawroriski 2019-03-11 19:13:49
Context
2019-03-11
19:16
Rename the base64 class files to end with data instead of class so that any potential verifiers/optimizers do not pick it up. check-in: 8e98c6fedd user: stephanie.gawroriski tags: trunk
19:13
Sort fields to group them together better. check-in: 352c832c8e user: stephanie.gawroriski tags: trunk
19:01
Process fields that are in a class. check-in: 15043484d6 user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/libs/tool-classfile/net/multiphasicapps/classfile/mini/Minimizer.java.

13
14
15
16
17
18
19

20
21
22
23
24
25
26
..
86
87
88
89
90
91
92





93
94
95
96
97
98
99
100
101
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;

import java.util.List;
import net.multiphasicapps.classfile.ClassFile;
import net.multiphasicapps.classfile.Field;
import net.multiphasicapps.classfile.InvalidClassFormatException;
import net.multiphasicapps.classfile.PrimitiveType;

/**
................................................................................
	private final __TempFields__[] __doFields()
	{
		// Static and instance fields are split because they are stored
		// in different places
		__TempFields__[] rv = new __TempFields__[]{
			new __TempFields__(), new __TempFields__()};
		





		// Process each field
		for (Field f : this.input.fields())
		{
			// These are stored in their own rows
			__TempFields__ temp = rv[(f.flags().isStatic() ? 1 : 0)];
			
			// Determine the size of this entry (and its alignment)
			PrimitiveType pt = f.type().primitiveType();
			int fsz = (pt == null ? 4 : pt.bytes());







>







 







>
>
>
>
>

|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.multiphasicapps.classfile.ClassFile;
import net.multiphasicapps.classfile.Field;
import net.multiphasicapps.classfile.InvalidClassFormatException;
import net.multiphasicapps.classfile.PrimitiveType;

/**
................................................................................
	private final __TempFields__[] __doFields()
	{
		// Static and instance fields are split because they are stored
		// in different places
		__TempFields__[] rv = new __TempFields__[]{
			new __TempFields__(), new __TempFields__()};
		
		// Perform some sorting to optimize slightly and make the layout a
		// bit friendlier
		List<Field> sorted = new ArrayList<>(this.input.fields());
		Collections.sort(sorted, new __MinimizerFieldSort__());
		
		// Process each field
		for (Field f : sorted)
		{
			// These are stored in their own rows
			__TempFields__ temp = rv[(f.flags().isStatic() ? 1 : 0)];
			
			// Determine the size of this entry (and its alignment)
			PrimitiveType pt = f.type().primitiveType();
			int fsz = (pt == null ? 4 : pt.bytes());

Added runt/libs/tool-classfile/net/multiphasicapps/classfile/mini/__MinimizerFieldSort__.java.















































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
// ---------------------------------------------------------------------------
// Multi-Phasic Applications: SquirrelJME
//     Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
//     Copyright (C) Multi-Phasic Applications <multiphasicapps.net>
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package net.multiphasicapps.classfile.mini;

import java.util.Comparator;
import net.multiphasicapps.classfile.Field;
import net.multiphasicapps.classfile.PrimitiveType;

/**
 * This is used to sort the input fields according to their size and type so
 * that they are grouped together and aligned together.
 *
 * Name sorting is used last.
 *
 * @since 2019/03/11
 */
final class __MinimizerFieldSort__
	implements Comparator<Field>
{
	/**
	 * Compares two fields.
	 *
	 * @param __a The first.
	 * @param __b The second.
	 * @since 2019/03/11
	 */
	public int compare(Field __a, Field __b)
	{
		// Compare sizes first to force alignables to be close to each other
		PrimitiveType pa = __a.type().primitiveType(),
			pb = __b.type().primitiveType();
		int sa = (pa == null ? 4 : pa.bytes()),
			sb = (pb == null ? 4 : pb.bytes());
		int rv = sa - sb;
		if (rv != 0)
			return rv;
		
		// Then sort by the descriptor so like-types are close to each other
		rv = __a.type().compareTo(__b.type());
		if (rv != 0)
			return rv;
		
		// Then fallback to name
		return __a.name().compareTo(__b.name());
	}
}