1 /* |
1 /* |
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
101 |
101 |
102 /** Usable size of all banks. */ |
102 /** Usable size of all banks. */ |
103 protected int size; |
103 protected int size; |
104 |
104 |
105 /** Offsets into all banks. */ |
105 /** Offsets into all banks. */ |
106 protected int offsets[]; |
106 protected int[] offsets; |
107 |
107 |
108 /* The current StateTrackable state. */ |
108 /* The current StateTrackable state. */ |
109 StateTrackableDelegate theTrackable; |
109 StateTrackableDelegate theTrackable; |
110 |
110 |
111 /** Size of the data types indexed by DataType tags defined above. */ |
111 /** Size of the data types indexed by DataType tags defined above. */ |
112 private static final int dataTypeSize[] = {8,16,16,32,32,64}; |
112 private static final int[] dataTypeSize = {8,16,16,32,32,64}; |
113 |
113 |
114 /** Returns the size (in bits) of the data type, given a datatype tag. |
114 /** Returns the size (in bits) of the data type, given a datatype tag. |
115 * @param type the value of one of the defined datatype tags |
115 * @param type the value of one of the defined datatype tags |
116 * @return the size of the data type |
116 * @return the size of the data type |
117 * @throws IllegalArgumentException if {@code type} is less than |
117 * @throws IllegalArgumentException if {@code type} is less than |
244 * {@code DataBuffer} |
244 * {@code DataBuffer} |
245 * @param offsets an array containing an offset for each bank. |
245 * @param offsets an array containing an offset for each bank. |
246 * @throws ArrayIndexOutOfBoundsException if {@code numBanks} |
246 * @throws ArrayIndexOutOfBoundsException if {@code numBanks} |
247 * does not equal the length of {@code offsets} |
247 * does not equal the length of {@code offsets} |
248 */ |
248 */ |
249 protected DataBuffer(int dataType, int size, int numBanks, int offsets[]) { |
249 protected DataBuffer(int dataType, int size, int numBanks, int[] offsets) { |
250 this(UNTRACKABLE, dataType, size, numBanks, offsets); |
250 this(UNTRACKABLE, dataType, size, numBanks, offsets); |
251 } |
251 } |
252 |
252 |
253 /** |
253 /** |
254 * Constructs a DataBuffer which contains the specified number |
254 * Constructs a DataBuffer which contains the specified number |
266 * @throws ArrayIndexOutOfBoundsException if {@code numBanks} |
266 * @throws ArrayIndexOutOfBoundsException if {@code numBanks} |
267 * does not equal the length of {@code offsets} |
267 * does not equal the length of {@code offsets} |
268 * @since 1.7 |
268 * @since 1.7 |
269 */ |
269 */ |
270 DataBuffer(State initialState, |
270 DataBuffer(State initialState, |
271 int dataType, int size, int numBanks, int offsets[]) |
271 int dataType, int size, int numBanks, int[] offsets) |
272 { |
272 { |
273 if (numBanks != offsets.length) { |
273 if (numBanks != offsets.length) { |
274 throw new ArrayIndexOutOfBoundsException("Number of banks" + |
274 throw new ArrayIndexOutOfBoundsException("Number of banks" + |
275 " does not match number of bank offsets"); |
275 " does not match number of bank offsets"); |
276 } |
276 } |
496 if (obj instanceof int[]) { |
496 if (obj instanceof int[]) { |
497 return (int[])obj; |
497 return (int[])obj; |
498 } else if (obj == null) { |
498 } else if (obj == null) { |
499 return null; |
499 return null; |
500 } else if (obj instanceof short[]) { |
500 } else if (obj instanceof short[]) { |
501 short sdata[] = (short[])obj; |
501 short[] sdata = (short[])obj; |
502 int idata[] = new int[sdata.length]; |
502 int[] idata = new int[sdata.length]; |
503 for (int i = 0; i < sdata.length; i++) { |
503 for (int i = 0; i < sdata.length; i++) { |
504 idata[i] = (int)sdata[i] & 0xffff; |
504 idata[i] = (int)sdata[i] & 0xffff; |
505 } |
505 } |
506 return idata; |
506 return idata; |
507 } else if (obj instanceof byte[]) { |
507 } else if (obj instanceof byte[]) { |
508 byte bdata[] = (byte[])obj; |
508 byte[] bdata = (byte[])obj; |
509 int idata[] = new int[bdata.length]; |
509 int[] idata = new int[bdata.length]; |
510 for (int i = 0; i < bdata.length; i++) { |
510 for (int i = 0; i < bdata.length; i++) { |
511 idata[i] = 0xff & (int)bdata[i]; |
511 idata[i] = 0xff & (int)bdata[i]; |
512 } |
512 } |
513 return idata; |
513 return idata; |
514 } |
514 } |