Program is losing an increment and two ``printf``s - java

In the method below, we set volatile int success = 0 and then enter a
while(!success) loop.
The loop increments tries, then enters a transaction, from within which we make a call to java sun.misc.Unsafe.putLong and we keep looping until the transaction succeeds.
so long as the debug flag __TRX_DEBUG__ is set, it will print the number of tries before returning.
Since that number is consistently zero, I have since added some "Hello" printfs.
The output of the program is
Hello0?!
putLong: (Lsun/misc/Unsafe;Ljava/lang/Class;Ljava/lang/Object;JJ)V with 0 tries
And I quite simply don't understand why.
/*
* Class: jnirtm_Transactionally
* Method: putLong
* Signature: (Lsun/misc/Unsafe;Ljava/lang/Class;Ljava/lang/Object;JJ)V
*/
jmethodID midPutLong = NULL;
JNIEXPORT void JNICALL Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ(
JNIEnv *env,
jclass _obsolete,
jobject unsafe,
jclass unsafe_class,
jobject base,
jlong off,
jlong value
){
if(midPutLong == NULL){
midPutLong = (*env)->GetMethodID(env,unsafe_class,"putLong","(Ljava/lang/Object;JJ)V");
#ifdef __TRX_ASSERT__
assert(midPutLong != NULL);
#endif
}
volatile int tries = 0;
volatile int success = 0;
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
printf("Hello0?!\n");
__asm__ __volatile__ (
"incl %0\n"
"xbegin 1f" /*1f: local label 1, look forward to find first*/
:"+rm"(tries)
:"rm"(success)/*artificial dependency to prevent re-ordering*/
);
/*do we need more artificial dependencies, here, to avoid re-ordering?*/
//unsafe.putInt(base,off,value);
printf("Hello1?!\n");
(*env)-> CallVoidMethod(env,unsafe,midPutLong,base,off,value);
printf("Hello2?!\n");
__asm__ __volatile__ (
"xend\n\t"
"incl %0\n" /*increment success ==> break out of loop*/
"jmp 2f\n" /*jump to end of loop*/
"1:\n" /*local label 1 (jumped to when transaction is aborted)*/
"2:" /*local label 2 (jumped to after a successfully completed transaction)*/
:"+rm"(success)
:"rm"(tries) /*artificial dependency*/
);
}
#ifdef __TRX_DEBUG__
printf("putLong: (Lsun/misc/Unsafe;Ljava/lang/Class;Ljava/lang/Object;JJ)V with %d tries\n",tries);
#endif
}
The interesting thing is that further up the file, I have a different method,
/*
* Class: jnirtm_Transactionally
* Method: putLong
* Signature: (Ljava/lang/Object;Ljava/lang/String;J)V
*/
JNIEXPORT void JNICALL Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J(JNIEnv* env, jclass _obsolete, jobject target, jstring fieldname, jlong value){
jclass targetClass = (*env)->GetObjectClass(env,target);
const char *str_fname = (*env)->GetStringUTFChars(env,fieldname,NULL);
jfieldID fidFLD = (*env)->GetFieldID(env, targetClass, str_fname, "J");
volatile int tries = 0;
volatile int success = 0;
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
__asm__ __volatile__ (
"incl %0\n"
"xbegin 1f" /*1f: local label 1, look forward to find first*/
:"+rm"(tries)
:"rm"(success)/*artificial dependency to prevent re-ordering*/
);
/*do we need more artificial dependencies, here, to avoid re-ordering?*/
(*env)->SetLongField(env,targetClass,fidFLD,value);
__asm__ __volatile__ (
"xend\n\t"
"incl %0\n" /*increment success ==> break out of loop*/
"jmp 2f\n" /*jump to end of loop*/
"1:\n" /*local label 1 (jumped to when transaction is aborted)*/
"2:" /*local label 2 (jumped to after a successfully completed transaction)*/
:"+rm"(success)
:"rm"(tries) /*artificial dependency*/
);
}
#ifdef __TRX_DEBUG__
printf("putLong: (Ljava/lang/Object;Ljava/lang/String;J)V with %d tries\n",tries);
#endif
}
which does essentially the same (except it's using a different method to change the data), but which consistently outputs
putLong: (Ljava/lang/Object;Ljava/lang/String;J)V with 1 tries
Each method gets called exactly once per run (from Java):
//requires base class acquisition and field index lookup
Transactionally.putLong(base$x, "x",3L);
assert(data.x == 3);
//requires callback to java which then invokes intrinsics
Transactionally.putLong(Transactionally.unsafe, Transactionally.unsafe_class, base$x, off$x, 4L);
assert(data.x == 4);
and that the program is running without throwing an assertion error is just adding to my confusion.
Because if assert(data.x == 4) does no throw an error, then
(*env)-> CallVoidMethod(env,unsafe,midPutLong,base,off,value);
in the first C method must have succeeded.
Yet it succeeded without executing the increment to tries before it started the transaction, nor did it execute the two printfs I inserted around it.
UPDATE
Adding the printfs to the second method will also not print them. So I guess being in a transaction suppresses IO and the behaviour is different only for the tries counter.
Why is this happening and how do I stop it?
UPDATE
Removed the hello printfs and wasn't sure how to create the asm code directly, so I instead disassembled the resulting .so file.
Zooming in on the parts that matter,
this is from the working method:
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
867: eb 41 jmp 8aa <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0xda>
__asm__ __volatile__ (
869: 8b 45 e4 mov -0x1c(%rbp),%eax
86c: 8b 55 e0 mov -0x20(%rbp),%edx
86f: ff c2 inc %edx
871: c7 f8 30 00 00 00 xbeginq 8a7 <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0xd7>
877: 89 55 e0 mov %edx,-0x20(%rbp)
:"rm"(success)/*artificial dependency to prevent re-ordering*/
);
/*do we need more artificial dependencies, here, to avoid re-ordering?*/
(*env)->SetLongField(env,targetClass,fidFLD,value);
[...]
8aa: 8b 45 e4 mov -0x1c(%rbp),%eax
8ad: 85 c0 test %eax,%eax
8af: 74 b8 je 869 <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0x99>
And this is from the faulty method:
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
968: eb 5b jmp 9c5 <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xfb>
__asm__ __volatile__ (
96a: 8b 45 fc mov -0x4(%rbp),%eax
96d: 8b 55 f8 mov -0x8(%rbp),%edx
970: ff c2 inc %edx
972: c7 f8 4a 00 00 00 xbeginq 9c2 <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xf8>
978: 89 55 f8 mov %edx,-0x8(%rbp)
);
/*do we need more artificial dependencies, here, to avoid re-ordering?*/
//unsafe.putLong(base,off,value);
(*env)-> CallVoidMethod(env,unsafe,midPutLong,base,off,value);
[...]
9c5: 8b 45 fc mov -0x4(%rbp),%eax
9c8: 85 c0 test %eax,%eax
9ca: 74 9e je 96a <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xa0>
I still don't see any relevant difference that would explain the behaviour.
Full Objdump
lib/libRTM_transact.so: file format elf64-x86-64
Disassembly of section .init:
0000000000000670 <_init>:
670: 48 83 ec 08 sub $0x8,%rsp
674: 48 8b 05 5d 09 20 00 mov 0x20095d(%rip),%rax # 200fd8 <__gmon_start__>
67b: 48 85 c0 test %rax,%rax
67e: 74 02 je 682 <_init+0x12>
680: ff d0 callq *%rax
682: 48 83 c4 08 add $0x8,%rsp
686: c3 retq
Disassembly of section .plt:
0000000000000690 <.plt>:
690: ff 35 72 09 20 00 pushq 0x200972(%rip) # 201008 <_GLOBAL_OFFSET_TABLE_+0x8>
696: ff 25 74 09 20 00 jmpq *0x200974(%rip) # 201010 <_GLOBAL_OFFSET_TABLE_+0x10>
69c: 0f 1f 40 00 nopl 0x0(%rax)
00000000000006a0 <printf#plt>:
6a0: ff 25 72 09 20 00 jmpq *0x200972(%rip) # 201018 <printf#GLIBC_2.2.5>
6a6: 68 00 00 00 00 pushq $0x0
6ab: e9 e0 ff ff ff jmpq 690 <.plt>
00000000000006b0 <__assert_fail#plt>:
6b0: ff 25 6a 09 20 00 jmpq *0x20096a(%rip) # 201020 <__assert_fail#GLIBC_2.2.5>
6b6: 68 01 00 00 00 pushq $0x1
6bb: e9 d0 ff ff ff jmpq 690 <.plt>
Disassembly of section .plt.got:
00000000000006c0 <.plt.got>:
6c0: ff 25 32 09 20 00 jmpq *0x200932(%rip) # 200ff8 <__cxa_finalize#GLIBC_2.2.5>
6c6: 66 90 xchg %ax,%ax
Disassembly of section .text:
00000000000006d0 <deregister_tm_clones>:
6d0: 48 8d 3d 59 09 20 00 lea 0x200959(%rip),%rdi # 201030 <_edata>
6d7: 48 8d 05 59 09 20 00 lea 0x200959(%rip),%rax # 201037 <_edata+0x7>
6de: 55 push %rbp
6df: 48 29 f8 sub %rdi,%rax
6e2: 48 89 e5 mov %rsp,%rbp
6e5: 48 83 f8 0e cmp $0xe,%rax
6e9: 76 15 jbe 700 <deregister_tm_clones+0x30>
6eb: 48 8b 05 de 08 20 00 mov 0x2008de(%rip),%rax # 200fd0 <_ITM_deregisterTMCloneTable>
6f2: 48 85 c0 test %rax,%rax
6f5: 74 09 je 700 <deregister_tm_clones+0x30>
6f7: 5d pop %rbp
6f8: ff e0 jmpq *%rax
6fa: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
700: 5d pop %rbp
701: c3 retq
702: 0f 1f 40 00 nopl 0x0(%rax)
706: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
70d: 00 00 00
0000000000000710 <register_tm_clones>:
710: 48 8d 3d 19 09 20 00 lea 0x200919(%rip),%rdi # 201030 <_edata>
717: 48 8d 35 12 09 20 00 lea 0x200912(%rip),%rsi # 201030 <_edata>
71e: 55 push %rbp
71f: 48 29 fe sub %rdi,%rsi
722: 48 89 e5 mov %rsp,%rbp
725: 48 c1 fe 03 sar $0x3,%rsi
729: 48 89 f0 mov %rsi,%rax
72c: 48 c1 e8 3f shr $0x3f,%rax
730: 48 01 c6 add %rax,%rsi
733: 48 d1 fe sar %rsi
736: 74 18 je 750 <register_tm_clones+0x40>
738: 48 8b 05 b1 08 20 00 mov 0x2008b1(%rip),%rax # 200ff0 <_ITM_registerTMCloneTable>
73f: 48 85 c0 test %rax,%rax
742: 74 0c je 750 <register_tm_clones+0x40>
744: 5d pop %rbp
745: ff e0 jmpq *%rax
747: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
74e: 00 00
750: 5d pop %rbp
751: c3 retq
752: 0f 1f 40 00 nopl 0x0(%rax)
756: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
75d: 00 00 00
0000000000000760 <__do_global_dtors_aux>:
760: 80 3d c9 08 20 00 00 cmpb $0x0,0x2008c9(%rip) # 201030 <_edata>
767: 75 27 jne 790 <__do_global_dtors_aux+0x30>
769: 48 83 3d 87 08 20 00 cmpq $0x0,0x200887(%rip) # 200ff8 <__cxa_finalize#GLIBC_2.2.5>
770: 00
771: 55 push %rbp
772: 48 89 e5 mov %rsp,%rbp
775: 74 0c je 783 <__do_global_dtors_aux+0x23>
777: 48 8b 3d aa 08 20 00 mov 0x2008aa(%rip),%rdi # 201028 <__dso_handle>
77e: e8 3d ff ff ff callq 6c0 <.plt.got>
783: e8 48 ff ff ff callq 6d0 <deregister_tm_clones>
788: 5d pop %rbp
789: c6 05 a0 08 20 00 01 movb $0x1,0x2008a0(%rip) # 201030 <_edata>
790: f3 c3 repz retq
792: 0f 1f 40 00 nopl 0x0(%rax)
796: 66 2e 0f 1f 84 00 00 nopw %cs:0x0(%rax,%rax,1)
79d: 00 00 00
00000000000007a0 <frame_dummy>:
7a0: 48 8d 3d 61 06 20 00 lea 0x200661(%rip),%rdi # 200e08 <__JCR_END__>
7a7: 48 83 3f 00 cmpq $0x0,(%rdi)
7ab: 75 0b jne 7b8 <frame_dummy+0x18>
7ad: e9 5e ff ff ff jmpq 710 <register_tm_clones>
7b2: 66 0f 1f 44 00 00 nopw 0x0(%rax,%rax,1)
7b8: 48 8b 05 29 08 20 00 mov 0x200829(%rip),%rax # 200fe8 <_Jv_RegisterClasses>
7bf: 48 85 c0 test %rax,%rax
7c2: 74 e9 je 7ad <frame_dummy+0xd>
7c4: 55 push %rbp
7c5: 48 89 e5 mov %rsp,%rbp
7c8: ff d0 callq *%rax
7ca: 5d pop %rbp
7cb: e9 40 ff ff ff jmpq 710 <register_tm_clones>
00000000000007d0 <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J>:
/*
* Class: jnirtm_Transactionally
* Method: putLong
* Signature: (Ljava/lang/Object;Ljava/lang/String;J)V
*/
JNIEXPORT void JNICALL Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J(JNIEnv* env, jclass _obsolete, jobject target, jstring fieldname, jlong value){
7d0: 55 push %rbp
7d1: 48 89 e5 mov %rsp,%rbp
7d4: 48 83 ec 50 sub $0x50,%rsp
7d8: 48 89 7d d8 mov %rdi,-0x28(%rbp)
7dc: 48 89 75 d0 mov %rsi,-0x30(%rbp)
7e0: 48 89 55 c8 mov %rdx,-0x38(%rbp)
7e4: 48 89 4d c0 mov %rcx,-0x40(%rbp)
7e8: 4c 89 45 b8 mov %r8,-0x48(%rbp)
jclass targetClass = (*env)->GetObjectClass(env,target);
7ec: 48 8b 45 d8 mov -0x28(%rbp),%rax
7f0: 48 8b 00 mov (%rax),%rax
7f3: 48 8b 80 f8 00 00 00 mov 0xf8(%rax),%rax
7fa: 48 8b 4d c8 mov -0x38(%rbp),%rcx
7fe: 48 8b 55 d8 mov -0x28(%rbp),%rdx
802: 48 89 ce mov %rcx,%rsi
805: 48 89 d7 mov %rdx,%rdi
808: ff d0 callq *%rax
80a: 48 89 45 e8 mov %rax,-0x18(%rbp)
const char *str_fname = (*env)->GetStringUTFChars(env,fieldname,NULL);
80e: 48 8b 45 d8 mov -0x28(%rbp),%rax
812: 48 8b 00 mov (%rax),%rax
815: 48 8b 80 48 05 00 00 mov 0x548(%rax),%rax
81c: 48 8b 75 c0 mov -0x40(%rbp),%rsi
820: 48 8b 4d d8 mov -0x28(%rbp),%rcx
824: ba 00 00 00 00 mov $0x0,%edx
829: 48 89 cf mov %rcx,%rdi
82c: ff d0 callq *%rax
82e: 48 89 45 f0 mov %rax,-0x10(%rbp)
jfieldID fidFLD = (*env)->GetFieldID(env, targetClass, str_fname, "J");
832: 48 8b 45 d8 mov -0x28(%rbp),%rax
836: 48 8b 00 mov (%rax),%rax
839: 48 8b 80 f0 02 00 00 mov 0x2f0(%rax),%rax
840: 48 8b 55 f0 mov -0x10(%rbp),%rdx
844: 48 8b 75 e8 mov -0x18(%rbp),%rsi
848: 48 8b 7d d8 mov -0x28(%rbp),%rdi
84c: 48 8d 0d ad 01 00 00 lea 0x1ad(%rip),%rcx # a00 <_fini+0x18>
853: ff d0 callq *%rax
855: 48 89 45 f8 mov %rax,-0x8(%rbp)
volatile int tries = 0;
859: c7 45 e0 00 00 00 00 movl $0x0,-0x20(%rbp)
volatile int success = 0;
860: c7 45 e4 00 00 00 00 movl $0x0,-0x1c(%rbp)
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
867: eb 41 jmp 8aa <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0xda>
__asm__ __volatile__ (
869: 8b 45 e4 mov -0x1c(%rbp),%eax
86c: 8b 55 e0 mov -0x20(%rbp),%edx
86f: ff c2 inc %edx
871: c7 f8 30 00 00 00 xbeginq 8a7 <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0xd7>
877: 89 55 e0 mov %edx,-0x20(%rbp)
:"rm"(success)/*artificial dependency to prevent re-ordering*/
);
/*do we need more artificial dependencies, here, to avoid re-ordering?*/
(*env)->SetLongField(env,targetClass,fidFLD,value);
87a: 48 8b 45 d8 mov -0x28(%rbp),%rax
87e: 48 8b 00 mov (%rax),%rax
881: 48 8b 80 70 03 00 00 mov 0x370(%rax),%rax
888: 48 8b 4d b8 mov -0x48(%rbp),%rcx
88c: 48 8b 55 f8 mov -0x8(%rbp),%rdx
890: 48 8b 75 e8 mov -0x18(%rbp),%rsi
894: 48 8b 7d d8 mov -0x28(%rbp),%rdi
898: ff d0 callq *%rax
__asm__ __volatile__ (
89a: 8b 45 e0 mov -0x20(%rbp),%eax
89d: 8b 55 e4 mov -0x1c(%rbp),%edx
8a0: 0f 01 d5 xend
8a3: ff c2 inc %edx
8a5: eb 00 jmp 8a7 <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0xd7>
8a7: 89 55 e4 mov %edx,-0x1c(%rbp)
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
8aa: 8b 45 e4 mov -0x1c(%rbp),%eax
8ad: 85 c0 test %eax,%eax
8af: 74 b8 je 869 <Java_jnirtm_Transactionally_putLong__Ljava_lang_Object_2Ljava_lang_String_2J+0x99>
:"+rm"(success)
:"rm"(tries) /*artificial dependency*/
);
}
#ifdef __TRX_DEBUG__
printf("putLong: (Ljava/lang/Object;Ljava/lang/String;J)V with %d tries\n",tries);
8b1: 8b 45 e0 mov -0x20(%rbp),%eax
8b4: 89 c6 mov %eax,%esi
8b6: 48 8d 3d 4b 01 00 00 lea 0x14b(%rip),%rdi # a08 <_fini+0x20>
8bd: b8 00 00 00 00 mov $0x0,%eax
8c2: e8 d9 fd ff ff callq 6a0 <printf#plt>
#endif
}
8c7: 90 nop
8c8: c9 leaveq
8c9: c3 retq
00000000000008ca <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ>:
jobject unsafe,
jclass unsafe_class,
jobject base,
jlong off,
jlong value
){
8ca: 55 push %rbp
8cb: 48 89 e5 mov %rsp,%rbp
8ce: 48 83 ec 40 sub $0x40,%rsp
8d2: 48 89 7d e8 mov %rdi,-0x18(%rbp)
8d6: 48 89 75 e0 mov %rsi,-0x20(%rbp)
8da: 48 89 55 d8 mov %rdx,-0x28(%rbp)
8de: 48 89 4d d0 mov %rcx,-0x30(%rbp)
8e2: 4c 89 45 c8 mov %r8,-0x38(%rbp)
8e6: 4c 89 4d c0 mov %r9,-0x40(%rbp)
if(midPutLong == NULL){
8ea: 48 8b 05 ef 06 20 00 mov 0x2006ef(%rip),%rax # 200fe0 <midPutLong##Base-0x58>
8f1: 48 8b 00 mov (%rax),%rax
8f4: 48 85 c0 test %rax,%rax
8f7: 75 61 jne 95a <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0x90>
midPutLong = (*env)->GetMethodID(env,unsafe_class,"putLong","(Ljava/lang/Object;JJ)V");
8f9: 48 8b 45 e8 mov -0x18(%rbp),%rax
8fd: 48 8b 00 mov (%rax),%rax
900: 48 8b 80 08 01 00 00 mov 0x108(%rax),%rax
907: 48 8b 75 d0 mov -0x30(%rbp),%rsi
90b: 48 8b 7d e8 mov -0x18(%rbp),%rdi
90f: 48 8d 0d 33 01 00 00 lea 0x133(%rip),%rcx # a49 <_fini+0x61>
916: 48 8d 15 44 01 00 00 lea 0x144(%rip),%rdx # a61 <_fini+0x79>
91d: ff d0 callq *%rax
91f: 48 89 c2 mov %rax,%rdx
922: 48 8b 05 b7 06 20 00 mov 0x2006b7(%rip),%rax # 200fe0 <midPutLong##Base-0x58>
929: 48 89 10 mov %rdx,(%rax)
#ifdef __TRX_ASSERT__
assert(midPutLong != NULL);
92c: 48 8b 05 ad 06 20 00 mov 0x2006ad(%rip),%rax # 200fe0 <midPutLong##Base-0x58>
933: 48 8b 00 mov (%rax),%rax
936: 48 85 c0 test %rax,%rax
939: 75 1f jne 95a <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0x90>
93b: 48 8d 0d be 01 00 00 lea 0x1be(%rip),%rcx # b00 <__PRETTY_FUNCTION__.3410>
942: ba 43 00 00 00 mov $0x43,%edx
947: 48 8d 35 1b 01 00 00 lea 0x11b(%rip),%rsi # a69 <_fini+0x81>
94e: 48 8d 3d 2d 01 00 00 lea 0x12d(%rip),%rdi # a82 <_fini+0x9a>
955: e8 56 fd ff ff callq 6b0 <__assert_fail#plt>
#endif
}
volatile int tries = 0;
95a: c7 45 f8 00 00 00 00 movl $0x0,-0x8(%rbp)
volatile int success = 0;
961: c7 45 fc 00 00 00 00 movl $0x0,-0x4(%rbp)
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
968: eb 5b jmp 9c5 <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xfb>
__asm__ __volatile__ (
96a: 8b 45 fc mov -0x4(%rbp),%eax
96d: 8b 55 f8 mov -0x8(%rbp),%edx
970: ff c2 inc %edx
972: c7 f8 4a 00 00 00 xbeginq 9c2 <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xf8>
978: 89 55 f8 mov %edx,-0x8(%rbp)
);
/*do we need more artificial dependencies, here, to avoid re-ordering?*/
//unsafe.putInt(base,off,value);
(*env)-> CallVoidMethod(env,unsafe,midPutLong,base,off,value);
97b: 48 8b 45 e8 mov -0x18(%rbp),%rax
97f: 48 8b 00 mov (%rax),%rax
982: 4c 8b 90 e8 01 00 00 mov 0x1e8(%rax),%r10
989: 48 8b 05 50 06 20 00 mov 0x200650(%rip),%rax # 200fe0 <midPutLong##Base-0x58>
990: 48 8b 10 mov (%rax),%rdx
993: 48 8b 7d c0 mov -0x40(%rbp),%rdi
997: 48 8b 4d c8 mov -0x38(%rbp),%rcx
99b: 48 8b 75 d8 mov -0x28(%rbp),%rsi
99f: 48 8b 45 e8 mov -0x18(%rbp),%rax
9a3: 4c 8b 4d 10 mov 0x10(%rbp),%r9
9a7: 49 89 f8 mov %rdi,%r8
9aa: 48 89 c7 mov %rax,%rdi
9ad: b8 00 00 00 00 mov $0x0,%eax
9b2: 41 ff d2 callq *%r10
__asm__ __volatile__ (
9b5: 8b 45 f8 mov -0x8(%rbp),%eax
9b8: 8b 55 fc mov -0x4(%rbp),%edx
9bb: 0f 01 d5 xend
9be: ff c2 inc %edx
9c0: eb 00 jmp 9c2 <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xf8>
9c2: 89 55 fc mov %edx,-0x4(%rbp)
while(!success){/*TODO: maybe switch to a different strategy when tries grows too large?*/
9c5: 8b 45 fc mov -0x4(%rbp),%eax
9c8: 85 c0 test %eax,%eax
9ca: 74 9e je 96a <Java_jnirtm_Transactionally_putLong__Lsun_misc_Unsafe_2Ljava_lang_Class_2Ljava_lang_Object_2JJ+0xa0>
:"+rm"(success)
:"rm"(tries) /*artificial dependency*/
);
}
#ifdef __TRX_DEBUG__
printf("putLong: (Lsun/misc/Unsafe;Ljava/lang/Class;Ljava/lang/Object;JJ)V with %d tries\n",tries);
9cc: 8b 45 f8 mov -0x8(%rbp),%eax
9cf: 89 c6 mov %eax,%esi
9d1: 48 8d 3d c0 00 00 00 lea 0xc0(%rip),%rdi # a98 <_fini+0xb0>
9d8: b8 00 00 00 00 mov $0x0,%eax
9dd: e8 be fc ff ff callq 6a0 <printf#plt>
#endif
}
9e2: 90 nop
9e3: c9 leaveq
9e4: c3 retq
Disassembly of section .fini:
00000000000009e8 <_fini>:
9e8: 48 83 ec 08 sub $0x8,%rsp
9ec: 48 83 c4 08 add $0x8,%rsp
9f0: c3 retq

No I/O can be performed can be performed in a transaction so the printf calls will likely abort the transaction. Then control passes to the 1: label, this is undefined behaviour as jumps between asm statements are not allowed, and eax is modified without being listed in the clobber or output lists.
The target of xbegin needs to be in the same asm statement or be a C label referenced using the asm goto extension. Or better use the intrinsics and avoid inline assembly.

Related

Java SSL/TLS Handshake

im writing a small HTTP/S Server for an Embeded Device Framework.
Because i use plain Java Sockets i need to implement the TLS/SSL myself.
For the Client Handshake i wrote following Function:
if (secureIO) {
// Print Message if Client Handshake was correct.
((SSLSocket) clientIO)
.addHandshakeCompletedListener(new HandshakeCompletedListener() {
#Override
public void handshakeCompleted(HandshakeCompletedEvent eventIO) {
logIO.debug(GuardianLog.Type.SUCCESS,
"Handshake with Client "
+ clientIO.getInetAddress().getHostAddress() + " via Method "
+ eventIO + " was correct.");
// Unlock Stream Lock.
lockIO[0] = false;
}
});
// ((SSLSocket) clientIO).setNeedClientAuth(true);
// Session Creation Blocks everything...
((SSLSocket) clientIO).setEnableSessionCreation(true);
// Set Cipher and Protocols for Client.
((SSLSocket) clientIO)
.setEnabledProtocols(((SSLServerSocket) tcpIO).getEnabledProtocols());
((SSLSocket) clientIO)
.setEnabledCipherSuites(
((SSLServerSocket) tcpIO).getEnabledCipherSuites());
// Start Handshake to Client.
((SSLSocket) clientIO).startHandshake();
}
The Problem is, when i opening the Socket Port in the Browser, the Page loads forever.
So i tried to debug the SSLSocket with OPENSSL it seems that the Handshake gets not fully finished.
I thought some Stream gets confused by an Listener on my Server, but i disabled the Input/Output Stream entirely with the lock bool, until the Handshake Complete Listener gets executed.
Some outstanding Debug Traces from the Server have given me this theory.
javax.net.ssl|ALL|1C|Server-Socket|2022-07-08 21:51:57.696 CEST|SSLSessionImpl.java:250|Session initialized: Session(1657309917387|TLS_AES_256_GCM_SHA384)
javax.net.ssl|FINE|1C|Server-Socket|2022-07-08 21:51:57.696 CEST|SSLSocketOutputRecord.java:241|WRITE: TLS13 handshake, length = 50
javax.net.ssl|FINE|1C|Server-Socket|2022-07-08 21:51:57.697 CEST|SSLCipher.java:2013|Plaintext before ENCRYPTION (
0000: 04 00 00 2E 00 01 51 80 F9 1F 1E 31 01 01 00 20 ......Q....1...
0010: E5 5B CF E4 29 3B 0E 9F E4 12 D7 CD 8B 34 2C 22 .[..);.......4,"
0020: 0B 14 45 B3 E9 94 CC 62 64 C3 06 E4 4F 72 82 D3 ..E....bd...Or..
0030: 00 00 16 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
0040: 00 00 00 ...
)
javax.net.ssl|FINE|1C|Server-Socket|2022-07-08 21:51:57.697 CEST|SSLSocketOutputRecord.java:255|Raw write (
0000: 17 03 03 00 53 6B D3 EE EF C5 DD D2 E3 3F DF 15 ....Sk.......?..
0010: 13 87 A5 9E BB AC 0A 1F 1F 6A 77 50 B1 4D 51 39 .........jwP.MQ9
0020: 4D 0C 00 78 D1 4A D8 78 79 9A 79 7E AD EB 20 80 M..x.J.xy.y... .
0030: 91 C3 A5 14 33 FF 13 01 9B D6 37 7E 3A 7B 9F 7D ....3.....7.:...
0040: 03 E6 59 90 FF 9B E3 63 87 18 FD 84 37 C7 21 CA ..Y....c....7.!.
0050: A7 AC ED 25 C3 05 73 A8 ...%..s.
)
Heres an example of my Read Function, the InputStream is setet after the Socket.accpet() Method:
private void read(InputStream streamIO, java.net.Socket clientIO) {
// todo: Test Performance between execute and submit.
poolIO.execute(new Runnable() {
#Override
public void run() {
try {
// clientIO.isConnected() && !tcpIO.isClosed() &&
while (!shutdownIO && clientIO.isConnected() && !tcpIO.isClosed()) {
// Byte Buffer ho contains read Data.
// #todo: add buffer max size, read until -1 (EOF).
byte[] bufferIO = new byte[streamIO.available()];
// Read Data into Buffer and store (EOF).
int codeIO = streamIO.read(bufferIO);
if (codeIO != 0 || bufferIO.length != 0) {
System.out.println(codeIO);
System.out.println(bufferIO.length);
}
// Check if bytes in the Buffer.
if (bufferIO.length != 0 && streamIO.available() == 0) {
if (binaryIO)
binary(new Socket(clientIO), bufferIO);
if (stringIO)
string(new Socket(clientIO), new String(bufferIO, charsetIO));
}
if (eofIO && (codeIO == -1)) {
break;
}
// Sleep for 100 Milliseconds (CPU Usage)
Thread.sleep(100);
}
streamIO.reset();
streamIO.close();
clientIO.close();
disconnect(new Socket(clientIO));
// Clear Buffer Stream.
// bufferIO = new byte[0];
} catch (IOException | InterruptedException errorIO) {
if (errorIO.getMessage().equalsIgnoreCase("Stream closed.")
|| errorIO.getMessage().equalsIgnoreCase("Connection reset")) {
logIO.debug(GuardianLog.Type.INFO,
"Client with IP " + clientIO.getInetAddress().getHostAddress()
+ " disconnected from Server with Port " + networkIO.getPort()
+ ".");
disconnect(new Socket(clientIO));
} else if (errorIO.getMessage().equalsIgnoreCase("sleep interrupted")) {
logIO.debug(
GuardianLog.Type.WARNING, "Socket Thread interrupted.", errorIO);
} else
logIO.append(
GuardianLog.Type.ERROR, "Socket throw an Error ", errorIO);
}
}
});
}

Extract .gz files in java

I'm trying to unzip some .gz files in java. After some researches i wrote this method:
public static void gunzipIt(String name){
byte[] buffer = new byte[1024];
try{
GZIPInputStream gzis = new GZIPInputStream(new FileInputStream("/var/www/html/grepobot/API/"+ name + ".txt.gz"));
FileOutputStream out = new FileOutputStream("/var/www/html/grepobot/API/"+ name + ".txt");
int len;
while ((len = gzis.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
gzis.close();
out.close();
System.out.println("Extracted " + name);
} catch(IOException ex){
ex.printStackTrace();
}
}
when i try to execute it i get this error:
java.util.zip.ZipException: Not in GZIP format
how can i solve it? Thanks in advance for your help
Test a sample, correct, gzipped file to see whether the problem lies in your code or not.
There are many possible ways to build a (g)zip file. Your file may have been built differently from what Java's built-in support expects, and the fact that one uncompressor understands a compression variant is no guarantee that Java will also recognize that variant. Please verify exact file type with file and/or other uncompression utilities that can tell you which options were used when compressing it. You may also have a look at the file itself with a tool such as hexdump. This is the output of the following command:
$ hexdump -C lgpl-2.1.txt.gz | head
00000000 1f 8b 08 08 ed 4f a9 4b 00 03 6c 67 70 6c 2d 32 |.....O.K..lgpl-2|
00000010 2e 31 2e 74 78 74 00 a5 5d 6d 73 1b 37 92 fe 8e |.1.txt..]ms.7...|
00000020 ba 1f 81 d3 97 48 55 34 13 7b 77 73 97 78 2b 55 |.....HU4.{ws.x+U|
00000030 b4 44 d9 bc 95 25 2d 29 c5 eb ba ba aa 1b 92 20 |.D...%-)....... |
00000040 39 f1 70 86 99 17 29 bc 5f 7f fd 74 37 30 98 21 |9.p...)._..t70.!|
00000050 29 7b ef 52 9b da 58 c2 00 8d 46 bf 3c fd 02 d8 |){.R..X...F.<...|
00000060 da fe 3f ef 6f 1f ed cd 78 36 1b 4f ed fb f1 ed |..?.o...x6.O....|
00000070 78 3a ba b1 f7 8f ef 6e 26 97 96 fe 1d df ce c6 |x:.....n&.......|
00000080 e6 e0 13 f9 e7 57 57 56 69 91 db 37 c3 d7 03 7b |.....WWVi..7...{|
00000090 ed e6 65 93 94 7b fb fa a7 9f 7e 32 c6 5e 16 bb |..e..{....~2.^..|
In this case, I used standard gzip on this license text. The 1st few bytes are unique to GZipped files (although they do not specify variants) - if your file does not start with 1f 8b, Java will complain, regardless of remaining contents.
If the problem is due to the file, it is possible that other uncompression libraries available in Java may deal with the format correctly - for example, see Commons Compress
import com.horsefly.utils.GZIP;
import org.apache.commons.io.FileUtils;
....
String content = new String(new GZIP().decompresGzipToBytes(FileUtils.readFileToByteArray(fileName)), "UTF-8");
in case someone needs it.

Invalid session/connection in Openfire

We are running an openfire server with hazelcast plugin for clustering. Sometimes the client IP shows as null or Invalid session/connection in the XMPP Console, as shown in the image and when this is shown the clients get disconnected, and are never able to reconnect
The warn.log file shows:
2016.10.05 23:45:36 org.jivesoftware.openfire.nio.ConnectionHandler - Closing connection due to exception in session: (0x0002298E: nio
socket, server, null => 0.0.0.0/0.0.0.0:5222)
org.apache.mina.filter.codec.ProtocolDecoderException:
org.jivesoftware.openfire.nio.XMLNotWellFormedException: Character is
invalid in: ^V (Hexdump: 16 03 03 00 96 10 00 00 92 91 04 01 AC EF A4
1F 6D 28 E6 B0 99 33 B2 D6 87 2C 1B B1 DF 77 1E 1D D7 FB E5 47 7D 04
8A 5E B8 77 59 FA 31 80 68 BA C0 8C C8 A9 7E A0 7D 74 2D 68 EF E0 B1
35 32 05 1D EA 97 2B 27 CB A9 D8 38 6F C0 59 0C B4 AB AC 33 90 09 05
38 18 97 EC 6F 97 1E 7B 09 56 FD A8 CC B3 2B 15 CA 22 9B 8E 02 84 25
9F E7 90 72 2A 7D 84 12 10 4C 58 21 10 E6 C3 77 03 79 F0 4D 7C 7C 15
4C BD AD 24 72 7D B7 CD AD 53 4B 2F BF 3F AD E7 F0 D5 A4 2C 55 36 84
D0 74 14 03 03 00 01 01 16 03 03 00 40 95 06 24 78 2F 4A 9C 0D 92 22
EB 32 2A 03 13 35 4A 5A E6 44 2B 31 D7 48 99 4A BC AF 32 BE F5 D3 22
09 92 E2 1C 9E 14 EA 3D 76 93 31 D8 45 A1 D8 FB 46 E2 BD C6 42 59 E4
5B C2 24 73 77 01 DA 95)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:242)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)
at java.lang.Thread.run(Thread.java:745) Caused by: org.jivesoftware.openfire.nio.XMLNotWellFormedException: Character is
invalid in: ^V
at org.jivesoftware.openfire.nio.XMLLightweightParser.read(XMLLightweightParser.java:223)
at org.jivesoftware.openfire.nio.XMPPDecoder.doDecode(XMPPDecoder.java:41)
at org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:176)
at org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:232)
... 9 more
2016.10.05 23:46:51 com.hazelcast.nio.tcp.ReadHandler - [172.31.29.146]:5701 [openfire] [3.5.1] hz.openfire.IO.thread-in-0
Closing socket to endpoint Address[172.31.20.168]:5701,
Cause:java.io.EOFException: Remote socket closed!
2016.10.05 23:46:52 com.hazelcast.nio.tcp.TcpIpConnectionMonitor - [172.31.29.146]:5701 [openfire] [3.5.1] Removing connection to
endpoint Address[172.31.20.168]:5701 Cause => java.net.SocketException
{Connection refused to address /172.31.20.168:5701}, Error-Count: 5
2016.10.05 23:46:57 com.hazelcast.nio.tcp.ReadHandler - [172.31.29.146]:5701 [openfire] [3.5.1] hz.openfire.IO.thread-in-1
Closing socket to endpoint Address[172.31.29.47]:5701,
Cause:java.io.EOFException: Remote socket closed!
2016.10.05 23:46:58 com.hazelcast.nio.tcp.TcpIpConnectionMonitor - [172.31.29.146]:5701 [openfire] [3.5.1] Removing connection to
endpoint Address[172.31.29.47]:5701 Cause => java.net.SocketException
{Connection refused to address /172.31.29.47:5701}, Error-Count: 5
2016.10.05 23:46:59 com.hazelcast.map.impl.BasicMapContextQuerySupport - [172.31.29.146]:5701 [openfire] [3.5.1] Could not get results java.util.concurrent.ExecutionException:
com.hazelcast.spi.exception.TargetNotMemberException: Not Member!
target:Address[172.31.29.47]:5701, partitionId: -1, operation:
com.hazelcast.map.impl.operation.QueryOperation, service:
hz:impl:mapService
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponseOrThrowException(InvocationFuture.java:357)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.get(InvocationFuture.java:225)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.get(InvocationFuture.java:204)
at com.hazelcast.map.impl.BasicMapContextQuerySupport.addResultsOfPredicate(BasicMapContextQuerySupport.java:350)
at com.hazelcast.map.impl.BasicMapContextQuerySupport.query(BasicMapContextQuerySupport.java:249)
at com.hazelcast.map.impl.proxy.MapProxySupport.query(MapProxySupport.java:1136)
at com.hazelcast.map.impl.proxy.MapProxyImpl.entrySet(MapProxyImpl.java:575)
at com.hazelcast.map.impl.proxy.MapProxyImpl.entrySet(MapProxyImpl.java:560)
at org.jivesoftware.openfire.plugin.util.cache.ClusteredCache.entrySet(ClusteredCache.java:117)
at org.jivesoftware.util.cache.CacheWrapper.entrySet(CacheWrapper.java:130)
at org.jivesoftware.openfire.spi.RoutingTableImpl.leftCluster(RoutingTableImpl.java:1065)
at org.jivesoftware.openfire.cluster.ClusterManager$2.run(ClusterManager.java:118)
Caused by: com.hazelcast.spi.exception.TargetNotMemberException: Not
Member! target:Address[172.31.29.47]:5701, partitionId: -1, operation:
com.hazelcast.map.impl.operation.QueryOperation, service:
hz:impl:mapService
at com.hazelcast.spi.impl.operationservice.impl.Invocation.initInvocationTarget(Invocation.java:298)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.doInvoke(Invocation.java:222)
at com.hazelcast.spi.impl.operationservice.impl.Invocation.run(Invocation.java:262)
at com.hazelcast.spi.impl.operationservice.impl.TargetInvocation.run(TargetInvocation.java:29)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:745)
at com.hazelcast.util.executor.HazelcastManagedThread.executeRun(HazelcastManagedThread.java:76)
at com.hazelcast.util.executor.HazelcastManagedThread.run(HazelcastManagedThread.java:92)
at ------ End remote and begin local stack-trace ------.(Unknown Source)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponse(InvocationFuture.java:384)
at com.hazelcast.spi.impl.operationservice.impl.InvocationFuture.resolveApplicationResponseOrThrowException(InvocationFuture.java:334)
... 11 more
2016.10.05 23:47:01 com.hazelcast.spi.EventService - [172.31.29.146]:5701 [openfire] [3.5.1] Error while logging processing
event java.lang.NullPointerException
at org.jivesoftware.util.StringUtils.getBytes(StringUtils.java:1098)
at org.jivesoftware.openfire.plugin.util.cache.CacheListener.handleEntryEvent(CacheListener.java:68)
at org.jivesoftware.openfire.plugin.util.cache.CacheListener.entryRemoved(CacheListener.java:60)
at com.hazelcast.map.impl.MapListenerAdaptors$2$1.onEvent(MapListenerAdaptors.java:83)
at com.hazelcast.map.impl.InternalMapListenerAdapter.onEvent(InternalMapListenerAdapter.java:51)
at com.hazelcast.map.impl.MapEventPublishingService.callListener(MapEventPublishingService.java:90)
at com.hazelcast.map.impl.MapEventPublishingService.dispatchEntryEventData(MapEventPublishingService.java:102)
at com.hazelcast.map.impl.MapEventPublishingService.dispatchEvent(MapEventPublishingService.java:46)
at com.hazelcast.map.impl.MapEventPublishingService.dispatchEvent(MapEventPublishingService.java:33)
at com.hazelcast.map.impl.MapService.dispatchEvent(MapService.java:91)
at com.hazelcast.map.impl.MapService.dispatchEvent(MapService.java:61)
at com.hazelcast.spi.impl.eventservice.impl.EventPacketProcessor.process(EventPacketProcessor.java:53)
at com.hazelcast.spi.impl.eventservice.impl.RemoteEventPacketProcessor.run(RemoteEventPacketProcessor.java:38)
at com.hazelcast.util.executor.StripedExecutor$Worker.process(StripedExecutor.java:190)
at com.hazelcast.util.executor.StripedExecutor$Worker.run(StripedExecutor.java:174)
The error.log shows
2016.10.05 23:47:13 org.jivesoftware.openfire.SessionManager - Could not close socket
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast
instance is not active!
at com.hazelcast.spi.AbstractDistributedObject.getService(AbstractDistributedObject.java:93)
at com.hazelcast.map.impl.proxy.MapProxySupport.toData(MapProxySupport.java:1122)
at com.hazelcast.map.impl.proxy.MapProxyImpl.remove(MapProxyImpl.java:178)
at org.jivesoftware.openfire.plugin.util.cache.ClusteredCache.remove(ClusteredCache.java:96)
at org.jivesoftware.util.cache.CacheWrapper.remove(CacheWrapper.java:145)
at org.jivesoftware.openfire.spi.RoutingTableImpl.removeClientRoute(RoutingTableImpl.java:903)
at org.jivesoftware.openfire.SessionManager.removeSession(SessionManager.java:1234)
at org.jivesoftware.openfire.SessionManager.removeSession(SessionManager.java:1206)
at org.jivesoftware.openfire.SessionManager$ClientSessionListener.onConnectionClose(SessionManager.java:1409)
at org.jivesoftware.openfire.nio.NIOConnection.notifyCloseListeners(NIOConnection.java:260)
at org.jivesoftware.openfire.nio.NIOConnection.close(NIOConnection.java:242)
at org.jivesoftware.openfire.nio.ConnectionHandler.exceptionCaught(ConnectionHandler.java:161)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.exceptionCaught(DefaultIoFilterChain.java:672)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:102)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterAdapter.exceptionCaught(IoFilterAdapter.java:102)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextExceptionCaught(DefaultIoFilterChain.java:461)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1100(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.exceptionCaught(DefaultIoFilterChain.java:760)
at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:93)
at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)
at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)
at java.lang.Thread.run(Thread.java:745)
2016.10.05 23:47:13 org.jivesoftware.openfire.nio.ConnectionHandler - Closing connection due to error while processing message: dXNlcm5hbWU9Ijk2NjUwNDgxMTkxOCIscmVhbG09InhtcHAuc2F5ZmVhcHAuY29tIixjbm9uY2U9ImY2MmM2OWMxOGU4ZWEzM2Y5NmRhY2I0ODU4YzhiNTQwNWU0ZDRiMzVmM2U4NWNmNjk0OGJmNWE5M2Q0MDAzNmIiLG5jPTAwMDAwMDAxLHFvcD1hdXRoLGRpZ2VzdC11cmk9InhtcHAveG1wcC5zYXlmZWFwcC5jb20iLHJlc3BvbnNlPTY3ODQ0MDM0ZjA5ZDc4YzQyODFmN2E1YzhmMGMyNDFhLGNoYXJzZXQ9dXRmLTgsbm9uY2U9IlpCME1CUVBwNFZsT2RxTWhIZTQwcWIxTHh4b1NoNkZwRDhRaXZKUm4i
com.hazelcast.core.HazelcastInstanceNotActiveException: Hazelcast
instance is not active!
at com.hazelcast.spi.AbstractDistributedObject.getService(AbstractDistributedObject.java:93)
at com.hazelcast.map.impl.proxy.MapProxySupport.toData(MapProxySupport.java:1122)
at com.hazelcast.map.impl.proxy.MapProxyImpl.get(MapProxyImpl.java:81)
at org.jivesoftware.openfire.plugin.util.cache.ClusteredCache.get(ClusteredCache.java:92)
at org.jivesoftware.util.cache.CacheWrapper.get(CacheWrapper.java:140)
at org.jivesoftware.openfire.lockout.LockOutManager.getUserLockOut(LockOutManager.java:244)
at org.jivesoftware.openfire.lockout.LockOutManager.getDisabledStatus(LockOutManager.java:152)
at org.jivesoftware.openfire.lockout.LockOutManager.isAccountDisabled(LockOutManager.java:163)
at org.jivesoftware.openfire.net.SASLAuthentication.authenticationSuccessful(SASLAuthentication.java:682)
at org.jivesoftware.openfire.net.SASLAuthentication.handle(SASLAuthentication.java:357)
at org.jivesoftware.openfire.net.StanzaHandler.process(StanzaHandler.java:191)
at org.jivesoftware.openfire.nio.ConnectionHandler.messageReceived(ConnectionHandler.java:180)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)
at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)
at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)
at org.apache.mina.core.filterchain.IoFilterAdapter.messageReceived(IoFilterAdapter.java:109)
Kindly help me with this. Thanks!
Regards,
Iqbal

Java serialization with empty and substrings

Had a look at the implementation and haven't been able to think of an explanation to this but maybe someone here will know.
public static void main(String[] args) throws Exception {
List<String> emptyStrings = new ArrayList<String>();
List<String> emptySubStrings = new ArrayList<String>();
for (int i = 0; i < 20000; i++) {
String actuallyEmpty = "";
String subStringedEmpty = " ";
subStringedEmpty = subStringedEmpty.substring(0, 0);
emptyStrings.add(actuallyEmpty);
emptySubStrings.add(subStringedEmpty);
}
System.out.println("Substring test");
// Write to files
long time = System.currentTimeMillis();
writeObjectToFile(emptyStrings, "empty.list");
System.out.println("Time taken to write empty list " + (System.currentTimeMillis() - time));
time = System.currentTimeMillis();
writeObjectToFile(emptySubStrings, "substring.list");
System.out.println("Time taken to write substring list " + (System.currentTimeMillis() - time));
//Read from files
time = System.currentTimeMillis();
List<String> readEmptyString = readObjectFromFile("empty.list");
System.out.println("Time taken to read empty list " + (System.currentTimeMillis() - time));
time = System.currentTimeMillis();
List<String> readEmptySubStrings = readObjectFromFile("substring.list");
System.out.println("Time taken to read substring list " + (System.currentTimeMillis() - time));
}
private static void writeObjectToFile(Object o, String file) throws Exception {
FileOutputStream out = new FileOutputStream(file);
ObjectOutputStream oout = new ObjectOutputStream(out);
oout.writeObject(o);
oout.flush();
oout.close();
}
private static <T> T readObjectFromFile(String file) throws Exception {
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(new FileInputStream(file));
return (T) ois.readObject();
} finally {
ois.close();
}
}
Ultimately these 2 lists contain 20,000 empty strings (one list contains "" empty strings and the other contains empty strings generated by substring(0,0)). But if you check the sizes of the serialized files generated (empty.list and substring.list) you will notice that the empty.list contains substantially more data.
I have noticed that the callers of remote EJB's which un-serialize these substring objects seem to have severe performance issues also.
The sizes of the lists are different because java uses a mechanism to store multiples references to the same object, like described:
References to other objects (except in transient or static fields)
cause those objects to be written also. Multiple references to a
single object are encoded using a reference sharing mechanism so that
graphs of objects can be restored to the same shape as when the
original was written.
see ObjectOutputStream
If you look the generated serialized file, you will see:
With 1 String empty inside:
empty.list:
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 01 77 04 00 00 00 01 74 00 00 78
The string "" corresponds to the last three bytes (00 00 78)
substring.list
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 01 77 04 00 00 00 01 74 00 00 78
Note that with one element the resulted file is the same.
But if we want to add more times the same object, we will be faced with other behavior.
Look the respective files with 2 times that string.
empty.list:
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 02 77 04 00 00 00 02 74 00 00 71 00 7e 00
02 78
substring.list
ac ed 00 05 73 72 00 13 6a 61 76 61 2e 75 74 69
6c 2e 41 72 72 61 79 4c 69 73 74 78 81 d2 1d 99
c7 61 9d 03 00 01 49 00 04 73 69 7a 65 78 70 00
00 00 02 77 04 00 00 00 02 74 00 00 74 00 00 78
Note that substring continues "normal", two non related strings with different references. But empty has some extra bytes to handle the issue of same reference.
Six bytes from substring (00 00 74 00 00 78) versus eight bytes from emptylist (00 00 71 00 7e 00 02 78)
This goes wrong because every repeated string that you add, more extra bytes are added. So when you full your arrayList there will be a lot of extra bytes to make it possible to reconstruct as it's original way.
If you want to know why there is that sharing mechanism, I suggest you to take a look at this question:
What is the meaning of reference sharing in Serialization? How Enums are Serialized?
empty.list contains one String object and lots of references to it.
substring.list contains 2000 string objects, all of them are equal in content.
You could "fix" this by intern()ing the strings.
private void verify(String name, Supplier<String> stringSupplier) throws IOException, ClassNotFoundException {
List<String> inputStrings = new ArrayList<String>();
inputStrings.add(stringSupplier.get());
inputStrings.add(stringSupplier.get());
ByteArrayOutputStream boas = new ByteArrayOutputStream();
ObjectOutputStream emptyOut = new ObjectOutputStream(boas);
emptyOut.writeObject(inputStrings);
emptyOut.flush();
ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(boas.toByteArray()));
List<String> returnedStrings = (List<String>)ois.readObject();
if(returnedStrings.get(0) == returnedStrings.get(1)) {
System.out.println(name + " contains the same object");
} else {
System.out.println(name + " contains DIFFERENT objects");
}
}
#Test
public void test() throws IOException, ClassNotFoundException {
verify("empty string", new Supplier<String>() {
#Override
public String get() {
return "";
}
});
verify("sub string", new Supplier<String>() {
#Override
public String get() {
String data = " ";
return data.substring(0, 0);
}
});
verify("intern()ed substring", new Supplier<String>() {
#Override
public String get() {
String data = " ";
return data.substring(0, 0).intern();
}
});
}

compile-time error: illegal Character: \8279

When I try to compile my servlet I get folowing exception:
illegal character: \8279
And it's pointing to &
msg.setContent("<a href=\"" + server +
":8080/myApp/ResetPasswordPage.jsp?randNum=" + randNum + ‌​
"&practiceName=" + practiceName+"\" Click Here </a>",
"text/html" );
I can't find a whole lot on the net about it...
I tried to copy this String to a java file in Eclipse. When I tried to save it I got :
There are 2 problematic invisible characters just after randNum +.
Remove them.
This is a dump of a copy-and-paste of your code:
00000010 3c 61 20 68 72 65 66 3d 5c 22 22 20 2b 20 73 65 |<a href=\"" + se|
00000020 72 76 65 72 20 2b 20 0a 20 20 20 20 20 20 20 20 |rver + . |
00000030 20 20 20 20 20 20 20 22 3a 38 30 38 30 2f 6d 79 | ":8080/my|
00000040 41 70 70 2f 52 65 73 65 74 50 61 73 73 77 6f 72 |App/ResetPasswor|
00000050 64 50 61 67 65 2e 6a 73 70 3f 72 61 6e 64 4e 75 |dPage.jsp?randNu|
00000060 6d 3d 22 20 2b 20 72 61 6e 64 4e 75 6d 20 2b 20 |m=" + randNum + |
00000070 e2 80 8c e2 80 8b 0a 20 20 20 20 20 20 20 20 20 |....... |
00000080 20 20 20 20 20 20 22 26 70 72 61 63 74 69 63 65 | "&practice|
00000090 4e 61 6d 65 3d 22 20 2b 20 70 72 61 63 74 69 63 |Name=" + practic|
000000a0 65 4e 61 6d 65 2b 22 5c 22 20 43 6c 69 63 6b 20 |eName+"\" Click |
Note the e2 80 8c and e2 80 8b between randNum + and the next line. You need to remove those.

Categories