ByteCode.News
Submit RSS Atom Sign in

Back to the channels

#java

  1. * nevet joined #java
  2. * CodeGeek!~codegeek@about/java/CodeGeek changed the topic to: Welcome! || Read Channel Rules at https://javachannel.org/ before participating. || Paste limit is two lines; ~pastebin lists options. || No applets, please. || Minecraft, Android, and Javascript all have their own channel. || You are being logged.
  3. * Aedil joined #java
  4. pr3d4t0r :: yawn ::
  5. pr3d4t0r Good morning.
  6. pr3d4t0r dreamreal!! Come to #cime or the other channel when you have a moment?
  7. * metalmaniac joined #java
  8. * B_fd joined #java
  9. * zorone joined #java
  10. * rvalue joined #java
  11. * Aedil joined #java
  12. * marcel joined #java
  13. * kusanagi joined #java
  14. * B_fd joined #java
  15. * kusanagi joined #java
  16. * sa02irc joined #java
  17. * ferdna joined #java
  18. * stfstfm joined #java
  19. * sponkz joined #java
  20. * B_fd joined #java
  21. * Ragnor joined #java
  22. * Nemu64 joined #java
  23. * ForeverDreaming joined #java
  24. * LFK joined #java
  25. * agnivn joined #java
  26. * stewi joined #java
  27. * MikeBux joined #java
  28. * tabmow joined #java
  29. * Square2 joined #java
  30. * kathadris joined #java
  31. * mwnaylor joined #java
  32. * kcomhnal2 joined #java
  33. * polarian joined #java
  34. * agnivn joined #java
  35. * agnivn joined #java
  36. * xeno joined #java
  37. * tabmow joined #java
  38. * tabmow joined #java
  39. * domicron joined #java
  40. * stfstfm_ joined #java
  41. * stfstfm joined #java
  42. * nevet joined #java
  43. * CodeGeek!~codegeek@about/java/CodeGeek changed the topic to: Welcome! || Read Channel Rules at https://javachannel.org/ before participating. || Paste limit is two lines; ~pastebin lists options. || No applets, please. || Minecraft, Android, and Javascript all have their own channel. || You are being logged.
  44. * stfstfm_ joined #java
  45. * sa02irc joined #java
  46. * GreenResponse joined #java
  47. * nevet joined #java
  48. * CodeGeek!~codegeek@about/java/CodeGeek changed the topic to: Welcome! || Read Channel Rules at https://javachannel.org/ before participating. || Paste limit is two lines; ~pastebin lists options. || No applets, please. || Minecraft, Android, and Javascript all have their own channel. || You are being logged.
  49. * kcomhnall joined #java
  50. * MonsterAbyss joined #java
  51. * szkl joined #java
  52. * jamezp joined #java
  53. dreamreal aaaaand nevet should be back. Still finding transaction leaks. :/
  54. dreamreal still muted HERE, though. :D
  55. * linuxthebaddev1 joined #java
  56. * kcomhnal2 joined #java
  57. * P1RATEZ joined #java
  58. * agnivn joined #java
  59. * tronexte joined #java
  60. * agnivn joined #java
  61. * candinsky joined #java
  62. * waznot joined #java
  63. * stfstfm joined #java
  64. * magla joined #java
  65. * sa02irc joined #java
  66. * B_fd joined #java
  67. * phlox joined #java
  68. * candinsky left #java (Leaving)
  69. * phlox joined #java
  70. * stfstfm_ joined #java
  71. * kcomhnall joined #java
  72. * jamezp joined #java
  73. * B_fd joined #java
  74. * m joined #java
  75. dreamreal https://bytecode.news/posts/2026/04/boilerplate-three-ways
  76. javabot dreamreal's title: "Boilerplate Three Ways | bytecode.news"
  77. * Square2 joined #java
  78. * sponkz joined #java
  79. * jbosmans joined #java
  80. * B_fd joined #java
  81. * mawk joined #java
  82. mawk hi
  83. mawk is this calling 'new' under the hood? byte[] a = {1, 2, 3};
  84. mawk i.e. is this equivalent to byte[] a = new byte[3]; a[0] = 1; a[1] = 2; a[2] = 3;
  85. DoofusCanadensis doubt it
  86. * stfstfm joined #java
  87. DoofusCanadensis byte != Byte
  88. mawk I'm writing JavaCard and need to avoid 'new' as much as possible
  89. * JazzJackalope joined #java
  90. jbosmans if implementation details like that matter a lot i'd suggest investigating how to validate answers to such questions, i'm thinking it'll lead to reading bytecode (aka jvm assembly)
  91. * raj joined #java
  92. jbosmans which i never do because i don't work at that level of detail
  93. Chronos mawk: Yes, as far as I know, it's identical to: byte[] a = new byte[]{1, 2, 3};
  94. Chronos So I believe it does indeed call "new".
  95. Chronos (Corrections welcome.)
  96. ernimril Chronos, compile it and then check with javap
  97. Chronos In Java, every array is a full-fledged object.
  98. mawk hmmm
  99. jbosmans what ernimril said
  100. mawk thanks
  101. sonOfRa mawk: byte[] a = {1, 2, 3};
  102. sonOfRa oops
  103. sonOfRa mawk: https://javap.yawk.at/#lnBjVV
  104. nevet javap pastebin
  105. jbosmans also, https://godbolt.org ftw
  106. nevet Compiler Explorer
  107. sonOfRa true, but javap.yawk.at is made by (former) channel regular yawkat!
  108. jbosmans kudos for that ^
  109. mawk ah yes indeed sonOfRa , thanks!
  110. jbosmans as far as i can see creating a new array doesn't create a new object
  111. jbosmans static int[] square() { return new int[]{9999}; }
  112. ernimril jbosmans, what about the newarray ?
  113. jbosmans 0: iconst_1
  114. jbosmans 1: newarray int
  115. jbosmans 3: dup
  116. jbosmans 4: iconst_0
  117. jbosmans 5: sipush 9999
  118. mawk well it calls "newarray byte" so it must be allocating it on the heap
  119. mawk so I should do that only in the constructor of my applet so it's only called once
  120. mawk I can technically trigger the garbage collector but it has to be done manually and it's not portable, not every card has it
  121. jbosmans thanks for unbanning :)
  122. jbosmans mawk, there's the epsilon gc which doesn't do anything iirc, might be useful for measuring/.. to accomplish your goals
  123. mawk ah yeah, I can run this on a simulator on a pc
  124. jbosmans should you want to invest in that approach
  125. mawk thanks
  126. jbosmans mawk, assuming sarcasm, understand what you mean (i think). You could make it runnable on a pc if you can separate the dependencies from the code that's actually doing the work (or the work you care about)
  127. jbosmans overlapping msgs:)
  128. * jreicher joined #java
  129. jreicher mawk: are you really assigning the byte array something known at compile time? Or is that just how you wrote the example?
  130. * domicron4 joined #java
  131. mawk yes it's known at compile time
  132. mawk maybe if I set it as "final" it won't make an allocation
  133. jbosmans afaik object instantiations are extremely cheap on jvm
  134. ernimril it is on all modern jvms, yes, has been so for a long time. Also constants are quite often inlined by the compiler
  135. jbosmans ~jep 519
  136. javabot 'JEP 519: Compact Object Headers' can be found at http://openjdk.java.net/jeps/519
  137. nevet JEP 519: Compact Object Headers
  138. jbosmans also, it was pretty cheap before, too
  139. * mindCrime joined #java
  140. jbosmans (before java 25)
  141. jbosmans also, up to recently, i compiled some tools using docker to an ubuntu 18/debian 10 compatible binary
  142. jbosmans which really made a difference for cmdline tools
  143. jbosmans fwiw it was compatible by compiling in dedicated docker containers, i just upgraded the container OS versions
  144. jbosmans iirc i got java+spring+jdbc+postgres+code down to ~60mb, which was nice
  145. jreicher mawk: if it's known at compile time then declare it static and don't worry about the new. At worst it will only be done once, but perhaps not at all.
  146. jbosmans UPX compression could drive that down substantially, but that would take longer to execute (because of decompression)
  147. jreicher A good rule of thumb IMO is to always tell the compiler everything you know.
  148. mawk jbosmans: this is running on a smartcard, it's a a very small and slow microcontroller
  149. mawk with just a couple hundred bytes of RAM to spare, maybe a thousand
  150. jbosmans mawk, great to be working on that :-)
  151. jbosmans i actually recognized JavaCard
  152. jreicher Is it possible Java is not the best language for that kind of target? (Honest question; I have no experience in this area)
  153. mawk well there's no choice, java is all they run; in your credit card, your epassport, your SIM card
  154. mawk you can sometimes run C but you need to sell your soul for a NDA
  155. jbosmans mawk, which context? eid or alike?
  156. mawk I'm working on a PKI smartcard
  157. jbosmans sweet, iirc our eid runs JavaCard too
  158. mawk java is actually a sane choice for the application, the JVM is fully controlled by the OS and can apply all the static checks and security mitigations they want
  159. jbosmans crazy stuff
  160. mawk they can do stuff like rolling back transactions in case of tearing, skewing the clock inbetween instructions or running instructions several times to throw off side channel attacks; and also exceptions are an integral part of how the card communicates with the reader, that's how you set the APDU status codes
  161. jbosmans mawk, what jdk version are you working in?
  162. * kathadris joined #java
  163. mawk it's javacard 3.0.5
  164. mawk compiling with jdk 17
  165. jbosmans that's not too bad for such a restricted context
  166. jbosmans iirc records are already supported
  167. jbosmans best use those wherever they make sense
  168. jbosmans because both the compiler and jvm will know they're mean to be (shallowly) immutable
  169. jbosmans alas way post midnight, sweet dreams
  170. * zorone joined #java
  171. * zorone joined #java
  172. * ChaiTRex joined #java
  173. * Square2 joined #java
  174. * ChaiTRex joined #java
  175. dreamreal for javacard, eh
  176. dreamreal That's a little surprising
  177. mawk why?
  178. dreamreal javacard's not very common in the wild. What are you deploying it to?
  179. * zorone_ joined #java
  180. * kcomhnal2 joined #java
  181. * kcomhnal2 left #java
  182. mawk I'm currently trying to add remote management capabilities with public key crypto
  183. mawk like SIM cards have
  184. mawk then you can open a secure channel with the card even through an untrusted network
  185. mawk then the card will serve as a secure element to hold keys for mTLS or other things, in an embedded product, in SIM format
  186. * ChaiTRex joined #java
  187. mawk and it's running on a JCOP 4 smartcard from NXP
  188. dreamreal *nod* nice!
  189. mawk I have half of the secure channel thing working, I can request AES session keys from the card and then continue with AES and CMAC
  190. mawk but now I need to wrap the AES keys with a public key instead of transmitting them in cleartext
  191. dreamreal so I have VERY VERY VERY little experience with that profile, but in general you avoid allocations like the plague: new is fine *but* you reuse *everything* you can, so if you allocate an array, you reuse that array for the lifetime of the application
  192. mawk yeah indeed
  193. dreamreal It's like you're writing in MUMPS except with java syntax, wooo
  194. mawk I can request transient arrays which get cleared either on deselect or on reset (like if the application is selected several times on different logical channels or different interfaces like contact vs contactless)
  195. mawk but then it's not with new
  196. dreamreal I don't know if there's a GC on that profile at all: you'd want to allocate and preserve
  197. dreamreal unless things have changed! Like I said, I've got VERY little experience here, like "ooo I tried it once"
  198. mawk yeah some cards do have a GC but not all of them
  199. mawk some cards even have ints and not just bytes and shorts
  200. mawk luxurious
  201. mawk and you need to invoke the GC manually, and it will maybe run next time a command is received
  202. dreamreal I think I last did javacard on a lark for javaone 2007? maybe 2008?
  203. mawk ah yeah the standards were quite different then
  204. mawk I think the standard was still to use the VISA platform manager instead of being the globalplatform thing of now
  205. dreamreal Gosh, I don't remember that at all - we had this physical connection to the board, I don't even remember what it was called to install the application
  206. dreamreal I remember having a GPS available, which I thought was going to be great for basically building the apple tags using java
  207. dreamreal like how train car locators work: when connected to an open network, send an identifier ("package XYZ is at X:Y at 23:01")