Check-in [b9d162787e]

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

Overview
Comment:Implement encode of dual-pool data.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: b9d162787e1c8c78964111cfca9201e6a097a37f
User & Date: stephanie.gawroriski 2019-07-20 12:34:22
Context
2019-07-20
12:38
Deprecate the old pool stuff. check-in: c97997ac5b user: stephanie.gawroriski tags: trunk
12:34
Implement encode of dual-pool data. check-in: b9d162787e user: stephanie.gawroriski tags: trunk
11:37
Base determine of pool type and if it should go in the pool. check-in: 2be98b73af 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.

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


130



















































































			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)
				{
					// Determine the type of entry this is

					Object ev = e.value;













					MinimizedPoolEntryType etype =
						MinimizedPoolEntryType.ofClass(ev.getClass());
					
					// {@squirreljme.error JC4d Cannot store the given entry
					// because it not compatible with the static/run-time
					// state. (The pool type; The value type; Is the run-time
					// pool being processed?)}
					if (isruntime != etype.isRuntime())
						throw new IllegalStateException("JC4d " +
							etype + " " + ev + " " + isruntime);
					
					throw new todo.TODO();


























				}
				
				// Merge the value data on top of the base
				vaos.writeTo(tdos);
			}
			
			// The size of the pool in bytes
................................................................................
				break;
		}
		
		// Return the location of the data
		return new DualPoolEncodeResult(staticpooloff, staticpoolsize,
			runtimepooloff, runtimepoolsize);
	}
}





























































































|








|
>

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






|

|

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







 







|
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
118
119
120
121
122
123
124
125
126
127
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
...
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
			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)
				{
					// The first is always null and just contains some pool
					// information
					Object ev = e.value;
					if (e.index == 0)
					{
						// No tag, no parts, no size, entry count
						tdos.write(0);
						tdos.write(0);
						tdos.writeShort(0);
						tdos.writeInt(poolsize);
						
						// Skip
						continue;
					}
					
					// Determine the type of entry this is
					MinimizedPoolEntryType et =
						MinimizedPoolEntryType.ofClass(ev.getClass());
					
					// {@squirreljme.error JC4d Cannot store the given entry
					// because it not compatible with the static/run-time
					// state. (The pool type; The value type; Is the run-time
					// pool being processed?)}
					if (isruntime != et.isRuntime())
						throw new IllegalStateException("JC4d " +
							et + " " + ev + " " + isruntime);
					
					// Determine if the parts need to be wide
					int[] ep = e.parts();
					int epn = ep.length;
					boolean iswide = false;
					for (int j = 0; j < epn; j++)
					{
						int v = ep[j];
						if (v < 0 || v > 127)
							iswide = true;
					}
					
					// Encode the data
					byte[] ed = DualPoolEncoder.encodeValue(et, ep, iswide,
						ev);
					
					// Write table data
					tdos.writeByte(et.ordinal());
					tdos.writeByte((iswide ? -epn : epn));
					tdos.writeShort(ed.length);
					
					// Align the data
					while (((reloff + vdos.size()) & 3) != 0)
						vdos.writeByte(0);
					
					// Write value data
					tdos.writeInt(reloff + vdos.size());
					vdos.write(ed);
				}
				
				// Merge the value data on top of the base
				vaos.writeTo(tdos);
			}
			
			// The size of the pool in bytes
................................................................................
				break;
		}
		
		// Return the location of the data
		return new DualPoolEncodeResult(staticpooloff, staticpoolsize,
			runtimepooloff, runtimepoolsize);
	}
	
	/**
	 * Encodes the pool value.
	 *
	 * @param __t The type to encode.
	 * @param __p The parts.
	 * @param __wide Are the parts wide?
	 * @param __v The value.
	 * @return The encoded value data.
	 * @throws IOException On write errors.
	 * @throws NullPointerException On null arguments.
	 * @since 2019/07/20
	 */
	public static final byte[] encodeValue(MinimizedPoolEntryType __t,
		int[] __p, boolean __wide, Object __v)
		throws IOException, NullPointerException
	{
		if (__t == null || __p == null || __v == null)
			throw new NullPointerException("NARG");
		
		// Encode
		try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
			DataOutputStream dos = new DataOutputStream(baos))
		{
			// Depends on the type
			switch (__t)
			{
					// Encode strings into the pool
				case STRING:
					{
						// Record hashCode and the String size as simple
						// fields to read. Note that even though there is
						// the UTF length, the length of the actual string
						// could be useful. But only keep the lowest part
						// as that will be "good enough"
						dos.writeShort((short)__p[0]);
						dos.writeShort(Minimizer.__checkUShort(__p[1]));
						
						// Write string UTF data
						dos.writeUTF((String)__v);
						
						// Write NUL terminator so it can be directly used
						// as a UTF-8 C pointer
						dos.writeByte(0);
					}
					break;
					
					// Integer
				case INTEGER:
					dos.writeInt((Integer)__v);
					break;
					
					// Float
				case FLOAT:
					dos.writeInt(Float.floatToRawIntBits((Float)__v));
					break;
					
					// Everything else just consists of parts which are
					// either values to other indexes or an ordinal
				case ACCESSED_FIELD:
				case CLASS_NAME:
				case CLASS_NAMES:
				case CLASS_POOL:
				case DOUBLE:
				case LONG:
				case INVOKED_METHOD:
				case METHOD_DESCRIPTOR:
				case METHOD_INDEX:
				case USED_STRING:
					if (__wide)
						for (int i = 0, n = __p.length; i < n; i++)
							dos.writeShort(Minimizer.__checkUShort(__p[i]));
					else
						for (int i = 0, n = __p.length; i < n; i++)
							dos.writeByte(__p[i]);
					break;
				
				default:
					throw new todo.OOPS(__t.name());
			}
			
			// Return the encoded data
			return baos.toByteArray();
		}
	}
}