jtvar.inc 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 2011 by Jonas Maebe,
  4. member of the Free Pascal development team.
  5. This file implements support routines for threadvarq with FPC/JVM
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. function FpcImplicitPtrThreadVar.initialValue: JLObject;
  13. var
  14. owningClass: JLClass;
  15. begin
  16. { look up the clone method if we haven't done this yet }
  17. if not assigned(fCloneMethod) then
  18. begin
  19. owningClass:=fInstanceToClone.getClass;
  20. repeat
  21. try
  22. fCloneMethod:=owningClass.getDeclaredMethod('clone',[]);
  23. except
  24. on JLNoSuchMethodException do
  25. owningClass:=owningClass.getSuperClass;
  26. end;
  27. until assigned(fCloneMethod);
  28. { required to enable calling methods of non-public classes (e.g. a
  29. record type defined in the implementation of a unit) -- can cause
  30. security exceptions if the security manager doesn't allow this
  31. though... }
  32. if not fCloneMethod.isAccessible then
  33. fCloneMethod.setAccessible(true);
  34. end;
  35. { return a copy of the record/shortstring/set/... }
  36. result:=fCloneMethod.invoke(fInstanceToClone,[]);
  37. end;
  38. constructor FpcImplicitPtrThreadVar.create(initInstanceToClone: JLObject);
  39. begin
  40. fInstanceToClone:=initInstanceToClone;
  41. end;
  42. function FpcImplicitPtrThreadVar.getReadWriteReference: Pointer;
  43. begin
  44. { return the address of the record/shortstring/set/... }
  45. result:=Pointer(get);
  46. end;
  47. function FpcNormalArrayThreadVar.initialValue: JLObject;
  48. begin
  49. result:=fpc_dynarray_copy(fInstanceToClone,-1,-1,fArrDim,fArrTyp);
  50. end;
  51. constructor FpcNormalArrayThreadVar.create(initInstanceToClone: JLObject; arrdim: longint; arrtyp: widechar);
  52. begin
  53. inherited create(initInstanceToClone);
  54. fArrDim:=arrdim;
  55. fArrTyp:=arrtyp;
  56. end;
  57. function FpcBooleanThreadVar.initialValue: JLObject;
  58. var
  59. arr: TJBooleanArray;
  60. begin
  61. setlength(arr,1);
  62. result:=JLObject(arr);
  63. end;
  64. function FpcBooleanThreadVar.getReadWriteReference: PBoolean;
  65. var
  66. arr: TJBooleanArray;
  67. begin
  68. arr:=TJBooleanArray(get);
  69. result:=@arr[0];
  70. end;
  71. function FpcByteThreadVar.initialValue: JLObject;
  72. var
  73. arr: TJByteArray;
  74. begin
  75. setlength(arr,1);
  76. result:=JLObject(arr);
  77. end;
  78. function FpcByteThreadVar.getReadWriteReference: PShortint;
  79. var
  80. arr: TJByteArray;
  81. begin
  82. arr:=TJByteArray(get);
  83. result:=@arr[0];
  84. end;
  85. function FpcShortThreadVar.initialValue: JLObject;
  86. var
  87. arr: TJShortArray;
  88. begin
  89. setlength(arr,1);
  90. result:=JLObject(arr);
  91. end;
  92. function FpcShortThreadVar.getReadWriteReference: PSmallint;
  93. var
  94. arr: TJShortArray;
  95. begin
  96. arr:=TJShortArray(get);
  97. result:=@arr[0];
  98. end;
  99. function FpcIntThreadVar.initialValue: JLObject;
  100. var
  101. arr: TJIntArray;
  102. begin
  103. setlength(arr,1);
  104. result:=JLObject(arr);
  105. end;
  106. function FpcIntThreadVar.getReadWriteReference: PLongint;
  107. var
  108. arr: TJIntArray;
  109. begin
  110. arr:=TJIntArray(get);
  111. result:=@arr[0];
  112. end;
  113. function FpcLongThreadVar.initialValue: JLObject;
  114. var
  115. arr: TJLongArray;
  116. begin
  117. setlength(arr,1);
  118. result:=JLObject(arr);
  119. end;
  120. function FpcLongThreadVar.getReadWriteReference: PInt64;
  121. var
  122. arr: TJLongArray;
  123. begin
  124. arr:=TJLongArray(get);
  125. result:=@arr[0];
  126. end;
  127. function FpcCharThreadVar.initialValue: JLObject;
  128. var
  129. arr: TJCharArray;
  130. begin
  131. setlength(arr,1);
  132. result:=JLObject(arr);
  133. end;
  134. function FpcCharThreadVar.getReadWriteReference: PWideChar;
  135. var
  136. arr: TJCharArray;
  137. begin
  138. arr:=TJCharArray(get);
  139. result:=@arr[0];
  140. end;
  141. function FpcFloatThreadVar.initialValue: JLObject;
  142. var
  143. arr: TJFloatArray;
  144. begin
  145. setlength(arr,1);
  146. result:=JLObject(arr);
  147. end;
  148. function FpcFloatThreadVar.getReadWriteReference: PSingle;
  149. var
  150. arr: TJFloatArray;
  151. begin
  152. arr:=TJFloatArray(get);
  153. result:=@arr[0];
  154. end;
  155. function FpcDoubleThreadVar.initialValue: JLObject;
  156. var
  157. arr: TJDoubleArray;
  158. begin
  159. setlength(arr,1);
  160. result:=JLObject(arr);
  161. end;
  162. function FpcDoubleThreadVar.getReadWriteReference: PDouble;
  163. var
  164. arr: TJDoubleArray;
  165. begin
  166. arr:=TJDoubleArray(get);
  167. result:=@arr[0];
  168. end;
  169. function FpcPointerThreadVar.initialValue: JLObject;
  170. var
  171. arr: TJObjectArray;
  172. begin
  173. setlength(arr,1);
  174. arr[0]:=fInitVal;
  175. result:=JLObject(arr);
  176. end;
  177. constructor FpcPointerThreadVar.create(initVal: JLObject);
  178. begin
  179. fInitVal:=initVal;
  180. end;
  181. function FpcPointerThreadVar.getReadWriteReference: PPointer;
  182. var
  183. arr: TJObjectArray;
  184. begin
  185. arr:=TJObjectArray(get);
  186. result:=PPointer(@arr[0]);
  187. end;