// File: hoehermann[P]TypedJNI/typedjni.cpp
// Function: TypedJNIString::TypedJNIString(JNIEnv_*, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
TypedJNIString::TypedJNIString(JNIEnv *env, const std::string & str) {
    std::wstring_convert<std::codecvt_utf8_utf16<char16_t>,char16_t> convert; 
    std::u16string u16string = convert.from_bytes(str);
    if (u16string.size() > static_cast<size_t>(std::numeric_limits<jint>::max())) {
        throw TypedJNIError("Converted string length "+std::to_string(u16string.size())+" exceeds maximum "+std::to_string(std::numeric_limits<jint>::max())+".");
    }
    static_assert(sizeof(jchar) == sizeof(char16_t), "jchar is not as long as char16_t");
    jstring jstr = env->NewString(reinterpret_cast<const jchar*>(u16string.c_str()), static_cast<jint>(u16string.size()));
    if (jstr == NULL) {
        throw TypedJNIError("NewString failed for UTF-8 string '"+str+"'.");
    }
    jstrptr = std::shared_ptr<_jstring>(jstr, [this, env](jstring s){ 
        if (!persistent) { 
            env->DeleteLocalRef(s);
        }
    });
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x230, %rsp            # imm = 0x230
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
movq %rdi, %rax
movq %rax, -0x1f0(%rbp)
xorl %eax, %eax
movl %eax, %esi
callq 0xaff0
movq -0x1e8(%rbp), %rax
movb $0x0, 0x10(%rax)
leaq -0x78(%rbp), %rdi
callq 0xb010
jmp 0x95bb
movq -0x18(%rbp), %rdx
leaq -0xa8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0xb0c0
jmp 0x95d1
leaq -0xa8(%rbp), %rdi
callq 0xb130
movq %rax, -0x1f8(%rbp)
callq 0xb150
movl %eax, %ecx
movq -0x1f8(%rbp), %rax
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x97fa
movb $0x1, -0x169(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x200(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0xb130
movq %rax, %rsi
leaq -0x148(%rbp), %rdi
callq 0xb160
jmp 0x9633
leaq 0x4f05(%rip), %rsi      # 0xe53f
leaq -0x128(%rbp), %rdi
leaq -0x148(%rbp), %rdx
callq 0x5390
jmp 0x964f
leaq 0x4f02(%rip), %rdx      # 0xe558
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x5340
jmp 0x966b
callq 0xb150
movl %eax, %esi
leaq -0x168(%rbp), %rdi
callq 0xb240
jmp 0x9680
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x168(%rbp), %rdx
callq 0x5270
jmp 0x969c
leaq 0x4eec(%rip), %rdx      # 0xe58f
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x5340
jmp 0x96b8
movq -0x200(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x8e00
jmp 0x96cd
movq -0x200(%rbp), %rdi
movb $0x0, -0x169(%rbp)
leaq 0xc426(%rip), %rsi      # 0x15b08
leaq 0x18a7(%rip), %rdx      # 0xaf90
callq 0x3390
jmp 0x9a06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x99f1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x99e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x97de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x97d2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x97c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x97ba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x97ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x97a2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3180
leaq -0xe8(%rbp), %rdi
callq 0x3180
leaq -0x168(%rbp), %rdi
callq 0x3180
leaq -0x108(%rbp), %rdi
callq 0x3180
leaq -0x128(%rbp), %rdi
callq 0x3180
leaq -0x148(%rbp), %rdi
callq 0x3180
testb $0x1, -0x169(%rbp)
jne 0x97e9
jmp 0x97f5
movq -0x200(%rbp), %rdi
callq 0x31c0
jmp 0x99dc
movq -0x10(%rbp), %rax
movq %rax, -0x218(%rbp)
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0xb390
movq -0x220(%rbp), %rdi
movq %rax, -0x210(%rbp)
callq 0xb130
movq -0x218(%rbp), %rdi
movq -0x210(%rbp), %rsi
movl %eax, %edx
callq 0xb360
movq %rax, -0x208(%rbp)
jmp 0x9849
movq -0x208(%rbp), %rax
movq %rax, -0x178(%rbp)
cmpq $0x0, -0x178(%rbp)
jne 0x9963
movb $0x1, -0x1b9(%rbp)
movl $0x10, %edi
callq 0x3130
movq %rax, -0x228(%rbp)
movq -0x18(%rbp), %rdx
leaq 0x4ce2(%rip), %rsi      # 0xe56a
leaq -0x1b8(%rbp), %rdi
callq 0xae80
jmp 0x9896
leaq 0x4cf1(%rip), %rdx      # 0xe58e
leaq -0x198(%rbp), %rdi
leaq -0x1b8(%rbp), %rsi
callq 0x5340
jmp 0x98b2
movq -0x228(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0x8e00
jmp 0x98c7
movq -0x228(%rbp), %rdi
movb $0x0, -0x1b9(%rbp)
leaq 0xc22c(%rip), %rsi      # 0x15b08
leaq 0x16ad(%rip), %rdx      # 0xaf90
callq 0x3390
jmp 0x9a06
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x99dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x994a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
jmp 0x993e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x80(%rbp)
movl %eax, -0x84(%rbp)
leaq -0x198(%rbp), %rdi
callq 0x3180
leaq -0x1b8(%rbp), %rdi
callq 0x3180
testb $0x1, -0x1b9(%rbp)
jne 0x9955
jmp 0x9961
movq -0x228(%rbp), %rdi
callq 0x31c0
jmp 0x99dc
movq -0x1f0(%rbp), %rax
movq -0x178(%rbp), %rsi
movq %rax, -0x1e0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq -0x1e0(%rbp), %rdx
movq -0x1d8(%rbp), %rcx
leaq -0x1d0(%rbp), %rdi
callq 0x9a10
jmp 0x999f
movq -0x1f0(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0xb3b0
leaq -0x1d0(%rbp), %rdi
callq 0x49d0
leaq -0xa8(%rbp), %rdi
callq 0xb3e0
leaq -0x78(%rbp), %rdi
callq 0xb420
addq $0x230, %rsp            # imm = 0x230
popq %rbp
retq
leaq -0xa8(%rbp), %rdi
callq 0xb3e0
leaq -0x78(%rbp), %rdi
callq 0xb420
movq -0x1e8(%rbp), %rdi
callq 0x49d0
movq -0x80(%rbp), %rdi
callq 0x33c0
nopw %cs:(%rax,%rax)