Check-in [b5b3691094]

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

Overview
Comment:Base outer pool encoding logic.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:b5b36910941138278e6dbba98268d571a4b09177
User & Date: stephanie.gawroriski 2019-07-17 17:46:17
Context
2019-07-18
07:02
Backup developer notes. check-in: c86ede7865 user: squirreljme tags: trunk
2019-07-17
17:46
Base outer pool encoding logic. check-in: b5b3691094 user: stephanie.gawroriski tags: trunk
16:54
Base for encode and write call of the dual pool. check-in: 86d571356b user: stephanie.gawroriski tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to runt/libs/tool-classfile/dev/shadowtail/classfile/mini/DualPoolEncoder.java.

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



56




















57
58
59
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.classfile.mini;



import dev.shadowtail.classfile.pool.DualClassRuntimePoolBuilder;

import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * This contains the encoder for dual pools.
 *
 * @since 2019/07/17
 */
public final class DualPoolEncoder
{




	/**
	 * Not used.
	 *
	 * @since 2019/07/17
	 */
	private DualPoolEncoder()
	{
................................................................................
	}
	
	/**
	 * Encodes the dual pool to the given output stream and returns the
	 * result.
	 *
	 * @param __dp The dual-pool to encode.
	 * @param __out The stream to write to, if this is already a
	 * {@link DataOutputStream} then it will be used as such.
	 * @return The result with size information.
	 * @throws IOException On write errors.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/17
	 */
	public static final DualPoolEncodeResult encode(
		DualClassRuntimePoolBuilder __dp, OutputStream __out)
		throws IOException, NullPointerException
	{
		if (__dp == null || __out == null)
			throw new NullPointerException("NARG");
		
		// Use pre-existing data output or just wrap it?
		DataOutputStream dos = ((__out instanceof DataOutputStream) ?





























			(DataOutputStream)__out : new DataOutputStream(__out));
		



		throw new todo.TODO();




















	}
}








>
>

>











>
>
>
>







 







|
<












|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
|
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.classfile.mini;

import dev.shadowtail.classfile.pool.BasicPoolBuilder;
import dev.shadowtail.classfile.pool.BasicPoolEntry;
import dev.shadowtail.classfile.pool.DualClassRuntimePoolBuilder;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * This contains the encoder for dual pools.
 *
 * @since 2019/07/17
 */
public final class DualPoolEncoder
{
	/** The size of the table entries. */
	public static final int TABLE_ENTRY_SIZE =
		8;
	
	/**
	 * Not used.
	 *
	 * @since 2019/07/17
	 */
	private DualPoolEncoder()
	{
................................................................................
	}
	
	/**
	 * Encodes the dual pool to the given output stream and returns the
	 * result.
	 *
	 * @param __dp The dual-pool to encode.
	 * @param __out The stream to write to.

	 * @return The result with size information.
	 * @throws IOException On write errors.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/17
	 */
	public static final DualPoolEncodeResult encode(
		DualClassRuntimePoolBuilder __dp, OutputStream __out)
		throws IOException, NullPointerException
	{
		if (__dp == null || __out == null)
			throw new NullPointerException("NARG");
		
		// Wrap output
		DataOutputStream tdos = new DataOutputStream(__out);
		
		// Return values
		int staticpooloff = 0,
			staticpoolsize = 0,
			runtimepooloff = 0,
			runtimepoolsize = 0;
		
		// Write both of the pools
		for (boolean isruntime = false;; isruntime = true)
		{
			// Are we encoding the static or run-time pool?
			BasicPoolBuilder pool = (isruntime ? __dp.runtimePool() :
				__dp.classPool());
			
			// The size of the pool, used for the first entry
			int poolsize = pool.size();
			
			// This is the base offset where the pool is located
			if (isruntime)
				runtimepooloff = tdos.size();
			else
				staticpooloff = tdos.size();
			
			// Determine the relative offset to where the entry data will
			// exist
			int reloff = poolsize + TABLE_ENTRY_SIZE;
			
			// The value data is appended right after the pool data
			try (ByteArrayOutputStream vaos = new ByteArrayOutputStream();
				DataOutputStream vdos = new DataOutputStream(vaos))
			{
				// Write individual pool entries
				for (BasicPoolEntry e : pool)
				{
					throw new todo.TODO();
				}
				
				// Merge the value data on top of the base
				vaos.writeTo(tdos);
			}
			
			// The size of the pool in bytes
			if (isruntime)
				runtimepoolsize = tdos.size() - runtimepooloff;
			else
				staticpoolsize = tdos.size() - staticpooloff;
			
			// Stop processing after the run-time is done
			if (isruntime)
				break;
		}
		
		// Return the location of the data
		return new DualPoolEncodeResult(staticpooloff, staticpoolsize,
			runtimepooloff, runtimepoolsize);
	}
}

Changes to runt/libs/tool-classfile/dev/shadowtail/classfile/pool/BasicPoolBuilder.java.

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
...
124
125
126
127
128
129
130




















131
132
133
134
135
136
137
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.classfile.pool;



import java.util.LinkedHashMap;
import java.util.Map;


/**
 * This class is used to store and contain the basic constant pool which
 * consists of values, indexes, and parts.
 *
 * This class is thread safe.
 *
 * @since 2019/07/15
 */
public final class BasicPoolBuilder

{
	/** Entries which exist in the constant pool. */
	protected final Map<Object, BasicPoolEntry> entries =
		new LinkedHashMap<>();
	
	/**
	 * Base pool initialization.
................................................................................
	public final BasicPoolEntry getByValue(Object __v)
	{
		synchronized (this)
		{
			return this.entries.get(__v);
		}
	}




















	
	/**
	 * Returns the size of the constant pool.
	 *
	 * @return The pool size.
	 * @since 2019/07/15
	 */







>
>


>










>







 







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







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
...
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// ---------------------------------------------------------------------------
// SquirrelJME is under the GNU General Public License v3+, or later.
// See license.mkd for licensing and copyright information.
// ---------------------------------------------------------------------------

package dev.shadowtail.classfile.pool;

import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import net.multiphasicapps.collections.UnmodifiableIterator;

/**
 * This class is used to store and contain the basic constant pool which
 * consists of values, indexes, and parts.
 *
 * This class is thread safe.
 *
 * @since 2019/07/15
 */
public final class BasicPoolBuilder
	implements Iterable<BasicPoolEntry>
{
	/** Entries which exist in the constant pool. */
	protected final Map<Object, BasicPoolEntry> entries =
		new LinkedHashMap<>();
	
	/**
	 * Base pool initialization.
................................................................................
	public final BasicPoolEntry getByValue(Object __v)
	{
		synchronized (this)
		{
			return this.entries.get(__v);
		}
	}
	
	/**
	 * {@inheritDoc}
	 * @since 2019/07/17
	 */
	@Override
	public final Iterator<BasicPoolEntry> iterator()
	{
		// Get elements
		BasicPoolEntry[] elems;
		synchronized (this)
		{
			Map<Object, BasicPoolEntry> entries = this.entries;
			elems = entries.values().toArray(
				new BasicPoolEntry[entries.size()]);
		}
		
		// Iterate over
		return UnmodifiableIterator.<BasicPoolEntry>of(elems);
	}
	
	/**
	 * Returns the size of the constant pool.
	 *
	 * @return The pool size.
	 * @since 2019/07/15
	 */